我正在运行Symfony 1.3.6在Ubuntu 10.0.4 LTS上。在Symfony任务中使用路由生成URL
我写了一个Symfony任务,生成一个包含链接(URL)的报告。
这里是方法在我的任务类的代码段:
protected function execute($arguments = array(), $options = array())
{
//create a context
sfContext::createInstance($this->configuration);
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'Asset', 'Tag'));
...
$url = url_for("@foobar?cow=marymoo&id=42");
// Line 1
echo '<a href="'.$url.'">This is a test</a>';
// Line 2
echo link_to('This is a test', $url);
}
路线名称这样定义:
foobar:
url: /some/fancy/path/:cow/:id/hello.html
param: { module: mymodule, action: myaction }
当这个运行时,生成的链接是:
1行产生此输出:
./symfony/symfony/some/fancy/path/marymoo/42/hello.html
,而不是预期:
/some/fancy/path/marymoo/42/hello.html
线2产生一个错误:
Unable to find a matching route to generate url for params "array ( 'action' => 'symfony', 'module' => '.',)".
再次,预期网址是:
/some/fancy/path/marymoo/42/hello.html
我怎么可能会解决这个?
+1为漂亮,简洁的片段,它告诉我如何解决这个问题。我会稍微修改代码以适应我的工作,测试它,如果它有效,我会接受这个答案。 – morpheous 2010-07-20 07:03:08
它的工作原理!谢谢你,谢谢,谢谢! :) – morpheous 2010-07-20 08:36:57
我应该在哪里放这个片段?我不能在任务中调用$ this-> getRouting():/ – JavierIEH 2012-10-22 14:00:33