From 5ec506dd475866d243db58881a8a98d81ebbe6c6 Mon Sep 17 00:00:00 2001 From: Smaine Milianni Date: Thu, 1 Feb 2018 09:04:18 +0100 Subject: [PATCH 1/2] add Prefixing the Names of Imported Routes This PR follows this one https://github.com/symfony/symfony-docs/pull/9159 --- routing/external_resources.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/routing/external_resources.rst b/routing/external_resources.rst index 37242053b6c..7ed7fe00dd7 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -133,6 +133,31 @@ suppose you want to prefix all routes in the AppBundle with ``/site`` (e.g. The path of each route being loaded from the new routing resource will now be prefixed with the string ``/site``. +Prefixing the Names of Imported Routes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +You have the possibility to prefix all routes names with the ``@Route`` annotation. +Add a ``name`` property to the ``@Route`` annotation of the controller class and that will be considered the prefix of all route names + +.. code-block:: php + use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + + /** + * @Route("/blog", name="blog_") + */ + class BlogController extends Controller + { + /** + * @Route("/", defaults={"page": "1"}, name="index") + * @Route("/page/{page}", name="index_paginated") + */ + public function indexAction($page, $_format) { ... } + + /** + * @Route("/posts/{slug}", name="post") + */ + public function showAction(Post $post) { ... } + } + Adding a Host Requirement to Imported Routes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From f8b8e0dfd76bfc6b53b7b63497d5c186365dccff Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 2 Feb 2018 15:36:44 +0100 Subject: [PATCH 2/2] Some fixes and rewords --- routing/external_resources.rst | 58 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/routing/external_resources.rst b/routing/external_resources.rst index 7ed7fe00dd7..d89c9c30e30 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -134,30 +134,40 @@ The path of each route being loaded from the new routing resource will now be prefixed with the string ``/site``. Prefixing the Names of Imported Routes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You have the possibility to prefix all routes names with the ``@Route`` annotation. -Add a ``name`` property to the ``@Route`` annotation of the controller class and that will be considered the prefix of all route names - -.. code-block:: php - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; - - /** - * @Route("/blog", name="blog_") - */ - class BlogController extends Controller - { - /** - * @Route("/", defaults={"page": "1"}, name="index") - * @Route("/page/{page}", name="index_paginated") - */ - public function indexAction($page, $_format) { ... } - - /** - * @Route("/posts/{slug}", name="post") - */ - public function showAction(Post $post) { ... } - } - +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 3.4 + The feature to prefix route names was introduced in Symfony 3.4. + +You also have the possibility to prefix all route names defined in a controller +class with the ``name`` attribute of the ``@Route`` annotation:: + + use Symfony\Component\Routing\Annotation\Route; + + /** + * @Route(name="blog_") + */ + class BlogController extends Controller + { + /** + * @Route("/blog", name="index") + */ + public function indexAction() + { + // ... + } + + /** + * @Route("/blog/posts/{slug}", name="post") + */ + public function showAction(Post $post) + { + // ... + } + } + +In this example, the names of the routes will be ``blog_index`` and ``blog_post``. + Adding a Host Requirement to Imported Routes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~