January 16, 2018 Javier Eguiluz

In Symfony 3.4 and 4.0 we added the possibility of prefixing the names of all the routes defined in a controller class with the name option in the main @Route annotation. In the following example, the route names will be blog_index and blog_post :

1 2 3 4 5 6 7 8 9 10 11 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route ; /** @Route("/blog", name="blog_") */ class BlogController extends Controller { /** @Route("/", name="index") */ public function indexAction () { ... } /** @Route("/posts/{slug}", name="post") */ public function showAction ( Post $post ) { ... } }

In Symfony 4.1 we improved this feature adding a new name_prefix option to prefix the names of the routes imported in configuration files. This will allow for example to import a given file multiple times and also tweak the route names of some third-party library/bundle:

1 2 3 4 5 6 7 8 9 app : resource : ../controller/routing.yaml api : resource : ../controller/routing.yaml # this prefix is added to all the action route names name_prefix : api_ # this prefix is added to all the action URLs prefix : /api

This is how the above config would look when using the XML format: