1

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 ?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, it's a naming convention, but why not simply use front instead of _front? Why was this convention introduced? Maybe you should clarify that what the OP assumed is why the convention was introduced. It's not clear from this answer.
Choosing between "front" or "_front' ? That's what convention are for. Someone chose "_front". No reasons, just a need to name something. You can still use "front", if you prefer.
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.

2 Comments

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.
@AdrianFöder Can you point to the documentation that states that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.