Skip to content

Commit 48f453d

Browse files
SamanShafighwouterj
authored andcommitted
Update slash_in_parameter.rst
"name" in requirements is confusing, I had problem for doing the same and then after 2 days I found that the "name" should be same as the parameter, it is not part of symfony config requirements: name: .+
1 parent a4f7d51 commit 48f453d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cookbook/routing/slash_in_parameter.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ How to Allow a "/" Character in a Route Parameter
55
=================================================
66

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

1212
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``.
13+
matches the ``/hello/{userName}`` route, where ``{userName}`` equals ``Fabien/Kris``.
1414

1515
Configure the Route
1616
-------------------
@@ -27,10 +27,10 @@ a more permissive regex path.
2727
.. code-block:: yaml
2828
2929
_hello:
30-
path: /hello/{name}
30+
path: /hello/{userName}
3131
defaults: { _controller: AcmeDemoBundle:Demo:hello }
3232
requirements:
33-
name: .+
33+
userName: .+
3434
3535
.. code-block:: xml
3636
@@ -40,9 +40,9 @@ a more permissive regex path.
4040
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4141
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
4242
43-
<route id="_hello" path="/hello/{name}">
43+
<route id="_hello" path="/hello/{userName}">
4444
<default key="_controller">AcmeDemoBundle:Demo:hello</default>
45-
<requirement key="name">.+</requirement>
45+
<requirement key="userName">.+</requirement>
4646
</route>
4747
</routes>
4848
@@ -52,10 +52,10 @@ a more permissive regex path.
5252
use Symfony\Component\Routing\Route;
5353
5454
$collection = new RouteCollection();
55-
$collection->add('_hello', new Route('/hello/{name}', array(
55+
$collection->add('_hello', new Route('/hello/{userName}', array(
5656
'_controller' => 'AcmeDemoBundle:Demo:hello',
5757
), array(
58-
'name' => '.+',
58+
'userName' => '.+',
5959
)));
6060
6161
return $collection;
@@ -75,4 +75,4 @@ a more permissive regex path.
7575
}
7676
}
7777
78-
That's it! Now, the ``{name}`` parameter can contain the ``/`` character.
78+
That's it! Now, the ``{userName}`` parameter can contain the ``/`` character.

0 commit comments

Comments
 (0)