Skip to content

Commit 5ec506d

Browse files
authored
add Prefixing the Names of Imported Routes
This PR follows this one #9159
1 parent d260a11 commit 5ec506d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

routing/external_resources.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ suppose you want to prefix all routes in the AppBundle with ``/site`` (e.g.
133133
The path of each route being loaded from the new routing resource will now
134134
be prefixed with the string ``/site``.
135135

136+
Prefixing the Names of Imported Routes
137+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138+
You have the possibility to prefix all routes names with the ``@Route`` annotation.
139+
Add a ``name`` property to the ``@Route`` annotation of the controller class and that will be considered the prefix of all route names
140+
141+
.. code-block:: php
142+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
143+
144+
/**
145+
* @Route("/blog", name="blog_")
146+
*/
147+
class BlogController extends Controller
148+
{
149+
/**
150+
* @Route("/", defaults={"page": "1"}, name="index")
151+
* @Route("/page/{page}", name="index_paginated")
152+
*/
153+
public function indexAction($page, $_format) { ... }
154+
155+
/**
156+
* @Route("/posts/{slug}", name="post")
157+
*/
158+
public function showAction(Post $post) { ... }
159+
}
160+
136161
Adding a Host Requirement to Imported Routes
137162
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138163

0 commit comments

Comments
 (0)