假设我有一个操作:
/**
* @Route("/current")
*
* @return Response
*/
public function currentAction()
{
}
现在我需要为这个动作生成url。$this->generateUrl()
控制器的方法接受路由名称作为参数。显然,只要我使用注释,我就没有这样的名字。
有什么解决办法吗?
明白了:
/**
* @Route("/current", name="foobar")
*
* @return Response
*/
public function currentAction()
{
}
通过阅读资料找到了它,但实际上它也在文档中进行了解释:http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-名称
正如@Mihai Stancu所提到的,总是有一个默认名称:
使用@route注释定义的路由将被赋予一个默认名称,该名称由捆绑包名称、控制器名称和操作名称组成。
在这种情况下,它将是bundlename_controllername_current