From 1a8fa2fdcdca6130289249752fb79615cc0c7445 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 23 Mar 2018 18:02:35 +0100 Subject: [PATCH 1/3] Documented the trailing_slash_on_root option --- routing/external_resources.rst | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/routing/external_resources.rst b/routing/external_resources.rst index a242ff5d971..514730db3a5 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -147,6 +147,65 @@ suppose you want to prefix all application routes with ``/site`` (e.g. The path of each route being loaded from the new routing resource will now be prefixed with the string ``/site``. +.. note:: + + If any of the prefixed routes defines an empty path, Symfony adds a trailing + slash to it. In the previous example, an empty path prefixed with ``/site`` + will result in the ``/site/`` URL. If you want to avoid this behavior, set + the ``trailing_slash_on_root`` option to ``false``: + + .. configuration-block:: + + .. code-block:: php-annotations + + use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + + /** + * @Route("/site", "trailing_slash_on_root"="false") + */ + class DefaultController + { + // ... + } + + .. code-block:: yaml + + # config/routes.yaml + controllers: + resource: '../src/Controller/' + type: annotation + prefix: /site + trailing_slash_on_root: false + + .. code-block:: xml + + + + + + + + + .. code-block:: php + + // config/routes.php + use Symfony\Component\Routing\RouteCollection; + + $app = $loader->import('../src/Controller/', 'annotation'); + // the second argument is the $trailing_slash_on_root option + $app->addPrefix('/site', false); + // ... + + .. versionadded:: 4.1 + The ``trailing_slash_on_root`` option was introduced in Symfony 4.1. + Prefixing the Names of Imported Routes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 1e2fbce882c035368e88e8b1521f21e25822f5d8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 23 Mar 2018 18:07:25 +0100 Subject: [PATCH 2/3] Fixed the example after Nico's comments --- routing/external_resources.rst | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/routing/external_resources.rst b/routing/external_resources.rst index 514730db3a5..86c41598fc2 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -156,18 +156,6 @@ be prefixed with the string ``/site``. .. configuration-block:: - .. code-block:: php-annotations - - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; - - /** - * @Route("/site", "trailing_slash_on_root"="false") - */ - class DefaultController - { - // ... - } - .. code-block:: yaml # config/routes.yaml From f1dc4408c57bbf32d5cdc0da4a60119d9372e8e9 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 23 Mar 2018 18:07:49 +0100 Subject: [PATCH 3/3] Fixed the PHP argument name --- routing/external_resources.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routing/external_resources.rst b/routing/external_resources.rst index 86c41598fc2..1c996e75926 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -187,7 +187,7 @@ be prefixed with the string ``/site``. use Symfony\Component\Routing\RouteCollection; $app = $loader->import('../src/Controller/', 'annotation'); - // the second argument is the $trailing_slash_on_root option + // the second argument is the $trailingSlashOnRoot option $app->addPrefix('/site', false); // ...