Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4b4954

Browse files
committed
Documented the trailing_slash_on_root option
1 parent3d4a077 commitb4b4954

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎routing/external_resources.rst‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,53 @@ suppose you want to prefix all application routes with ``/site`` (e.g.
147147
The path of each route being loaded from the new routing resource will now
148148
be prefixed with the string ``/site``.
149149

150+
..note::
151+
152+
If any of the prefixed routes defines an empty path, Symfony adds a trailing
153+
slash to it. In the previous example, an empty path prefixed with ``/site``
154+
will result in the ``/site/`` URL. If you want to avoid this behavior, set
155+
the ``trailing_slash_on_root`` option to ``false``:
156+
157+
..configuration-block::
158+
159+
..code-block::yaml
160+
161+
# config/routes.yaml
162+
controllers:
163+
resource:'../src/Controller/'
164+
type:annotation
165+
prefix:/site
166+
trailing_slash_on_root:false
167+
168+
..code-block::xml
169+
170+
<!-- config/routes.xml-->
171+
<?xml version="1.0" encoding="UTF-8" ?>
172+
<routesxmlns="http://symfony.com/schema/routing"
173+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
174+
xsi:schemaLocation="http://symfony.com/schema/routing
175+
http://symfony.com/schema/routing/routing-1.0.xsd">
176+
177+
<import
178+
resource="../src/Controller/"
179+
type="annotation"
180+
prefix="/site"
181+
trailing-slash-on-root="false" />
182+
</routes>
183+
184+
..code-block::php
185+
186+
// config/routes.php
187+
use Symfony\Component\Routing\RouteCollection;
188+
189+
$app = $loader->import('../src/Controller/', 'annotation');
190+
// the second argument is the $trailingSlashOnRoot option
191+
$app->addPrefix('/site', false);
192+
// ...
193+
194+
..versionadded::4.1
195+
The ``trailing_slash_on_root`` option was introduced in Symfony 4.1.
196+
150197
Prefixing the Names of Imported Routes
151198
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152199

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp