Samuel Roze  - 3397cc9d55eb953351c84ed40e9425a7 - Prefix imported route names (Symfony Blog)

In 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 @ annotation. In the following example, the
route names will be _index and blog_post:

use SensioBundleFrameworkExtraBundleConfigurationRoute;

/** @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_ option to
prefix the names of the routes 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:

    resource: ../controller/routing.yaml

    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:

<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns=""

    <import resource="../controller/routing.xml" />
    <import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" />


Source link


Please enter your comment!
Please enter your name here