Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing routes to generate URLs in a Symfony task
    primarykey
    data
    text
    <p>I am running <a href="http://en.wikipedia.org/wiki/Symfony" rel="noreferrer">Symfony</a> 1.3.6 on Ubuntu 10.0.4 LTS.</p> <p>I have written a Symfony task that generates a report which contains links (URLs).</p> <p>Here is a snippet of the <code>execute()</code> method in my task class:</p> <pre><code> protected function execute($arguments = array(), $options = array()) { //create a context sfContext::createInstance($this-&gt;configuration); sfContext::getInstance()-&gt;getConfiguration()-&gt;loadHelpers(array('Url', 'Asset', 'Tag')); ... $url = url_for("@foobar?cow=marymoo&amp;id=42"); // Line 1 echo '&lt;a href="'.$url.'"&gt;This is a test&lt;/a&gt;'; // Line 2 echo link_to('This is a test', $url); } </code></pre> <p>The route name is defined like this:</p> <pre><code>foobar: url: /some/fancy/path/:cow/:id/hello.html param: { module: mymodule, action: myaction } </code></pre> <p>When this is run, the generated link is:</p> <p><strong>Line 1</strong> produces this output:</p> <blockquote> <p>./symfony/symfony/some/fancy/path/marymoo/42/hello.html</p> </blockquote> <p>instead of the expected:</p> <blockquote> <p>/some/fancy/path/marymoo/42/hello.html</p> </blockquote> <p><strong>Line 2</strong> generates an error:</p> <blockquote> <p>Unable to find a matching route to generate url for params "array ( 'action' => 'symfony', 'module' => '.',)".</p> </blockquote> <p>Again, the expected URL is:</p> <blockquote> <p>/some/fancy/path/marymoo/42/hello.html</p> </blockquote> <p>How may I resolve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload