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

Appearance settings

Commit d61dc78

Browse filesBrowse files
committed
[cookbook][routing] Proofreading the new slash in parameter cookbook entry
1 parent 6b7cca4 commit d61dc78
Copy full SHA for d61dc78

File tree

Expand file treeCollapse file tree

3 files changed

+17
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-8
lines changed

‎cookbook/index.rst

Copy file name to clipboardExpand all lines: cookbook/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Cookbook
88
controller/service
99

1010
routing/scheme
11+
routing/slash_in_parameter
1112

1213
assetic/yuicompressor
1314
templating/PHP

‎cookbook/map.rst.inc

Copy file name to clipboardExpand all lines: cookbook/map.rst.inc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* **Routing**
77

88
* :doc:`/cookbook/routing/scheme`
9+
* :doc:`/cookbook/routing/slash_in_parameter`
910

1011
* **Templating and Assets**
1112

‎cookbook/routing/slash_in_parameter.rst

Copy file name to clipboardExpand all lines: cookbook/routing/slash_in_parameter.rst
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
.. index::
22
single: Routing; Allow / in route parameter
33

4-
How to allow / character in a route parameter
5-
=============================================
4+
How to allow a "/" character in a route parameter
5+
=================================================
66

77
Sometimes, you need to compose URLs with parameters that can contain a slash
8-
``/``. But Symfony uses this character as separator between route parts.
8+
``/``. For example, take the classic ``/hello/{name}`` route. By default,
9+
``/hello/Fabien`` will match this route but not ``/hello/Fabien/Kris``. This
10+
is because Symfony uses this character as separator between route parts.
911

10-
Configure the route
12+
This guide covers how you can modify a route so that ``/hello/Fabien/Kris``
13+
matches the ``/hello/{name}`` route, where ``{name}`` equals ``Fabien/Kris``.
14+
15+
Configure the Route
1116
-------------------
1217

1318
By default, the symfony routing components requires that the parameters
1419
match the following regex pattern: ``[^/]+``. This means that all characters
15-
are allowed excepted ``/``.
20+
are allowed except ``/``.
1621

17-
You must explicitely allow ``/`` to be part of your parameter specifying
22+
You must explicitly allow ``/`` to be part of your parameter by specifying
1823
a more permissive regex pattern.
1924

2025
.. configuration-block::
@@ -55,7 +60,7 @@ a more permissive regex pattern.
5560
5661
return $collection;
5762
58-
.. code-block:: annotation
63+
.. code-block:: php-annotations
5964
6065
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6166
@@ -68,4 +73,6 @@ a more permissive regex pattern.
6873
{
6974
// ...
7075
}
71-
}
76+
}
77+
78+
That's it! Now, the ``{name}`` parameter can contain the ``/`` character.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.