zerkms
zerkms

Reputation: 254886

Route name for url generation 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 generate url to this action. $this->generateUrl() controller's method accepts route name as an argument. Obviously I have no such name as long as I use annotations.

Any workarounds for this?

Upvotes: 5

Views: 5166

Answers (1)

zerkms
zerkms

Reputation: 254886

Got it:

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

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

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

A route defined with the @Route annotation is given a default name composed of the bundle name, the controller name and the action name.

in this case it will be a bundlename_controllername_current

Upvotes: 15

Related Questions