What is the point of the name method in the symfony2 annotation?

89 views Asked by At
/**
*@Route ("/hello/{name}", name="_demo_hello")
*
**/

I saw this method in this youtube tutorial Go to 7:36 I wanted to know what is the significance of the "name" method? Can you make up the name method?

Thank you in advance.

1

There are 1 answers

0
Johann On

The name option when defining routes with annotations is useful if you want to customize the name of the route. By default, if there is no name specified, Symfony will generate a name based on the controller's action name, like this: indexAction in the WebController of the AppBundle => app_web_index

But you can use the name option to change that:

@Route ("/", name="homepage")

You can then use this name to refer to this route in your controllers or templates:

{{ path('homepage') }}