0

I'm working on a Symfony2 project and in the file routing.yml I have the following lines:

_front:
    resource: routing_front.yml

_admin:
    resource: routing_admin.yml
    prefix:   /admin

So this actually allows defining the routes for the front-end and the back-end in separate dedicated files.

What about the names though ? Is it simply a naming convention to start with an underscore - which will tell at first sight that the actual routes are in a different file - or has this an influence on how the framework handle those ?

Didier Ghys
  • 30,396
  • 9
  • 75
  • 81

2 Answers2

2

It's only a naming convention.

But the Framework will handle the routes by matching the first route defined with the matching url requested, then the second one and so on...

So in your case, even if you requested http://www.mysyte.com/admin/whatever, it will match this url with all the routes in routing_front.yml before matching them with routing_admin.yml

Med
  • 2,035
  • 20
  • 31
0

These names become particularly useful when you are creating links in twig templates - rather than hardcoding the URLs, you can generate absolute URLs based on the route names, e.g. :

<a href="{{ url('_welcome') }}">Welcome page</a>

The underscores make it more obviously a route, if you're a developer particularly far into Symfony-land (it is a convention), but they're definitely not required per se.

d0ug7a5
  • 692
  • 4
  • 7
  • 1
    this is definitely not a recommended practice to prefix route names with underscores in general! As the accepted answer suggests, prefixed route names are a convention to mark "private" routes like the profiler which are not meant for "actual" use in userland. – Adrian Föder May 24 '17 at 12:36