The name of the route to generate URLs when using annotations in Symfony 2

Let's say I have an action:

/**
 * @Route("/current")
 *
 * @return Response
 */
public function currentAction() 
{
}

And now I need to create a url for this action. $this->generateUrl()The controller method takes the name of the route as an argument. Obviously, I don't have that name as long as I use annotations.

Any workarounds for this?

+5
source share
1 answer

Got this:

/**
 * @Route("/current", name="foobar")
 *
 * @return Response
 */
public function currentAction() 
{
}

Found it by reading the sources, but in fact it is also explained in the documentation: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-name

As @Mihai Stancu mentioned - there is always a default name:

, @Route, , , .

bundlename_controllername_current

+15

All Articles