Skip to content

Commit d61dc78

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

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

cookbook/index.rst

+1
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

+1
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

+15-8
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)