Skip to content

Commit

Permalink
minor #4400 Continues #4307 (SamanShafigh, WouterJ)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

Continues #4307

Continues #4307

| Q   | A
| --- | ---
| Doc fix? | yes
| New docs? | no
| Applies to | all
| Fixed tickets | -

Original PR description:

 > "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

Commits
-------

b412780 Changed userName to username
48f453d Update slash_in_parameter.rst
  • Loading branch information
weaverryan committed Nov 20, 2014
2 parents c008733 + b412780 commit 188dd1f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cookbook/routing/slash_in_parameter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ How to Allow a "/" Character in a Route Parameter
=================================================

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

This guide covers how you can modify a route so that ``/hello/Fabien/Kris``
matches the ``/hello/{name}`` route, where ``{name}`` equals ``Fabien/Kris``.
matches the ``/hello/{username}`` route, where ``{username}`` equals ``Fabien/Kris``.

Configure the Route
-------------------
Expand All @@ -27,10 +27,10 @@ a more permissive regex path.
.. code-block:: yaml
_hello:
path: /hello/{name}
path: /hello/{username}
defaults: { _controller: AcmeDemoBundle:Demo:hello }
requirements:
name: .+
username: .+
.. code-block:: xml
Expand All @@ -40,9 +40,9 @@ a more permissive regex path.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="_hello" path="/hello/{name}">
<route id="_hello" path="/hello/{username}">
<default key="_controller">AcmeDemoBundle:Demo:hello</default>
<requirement key="name">.+</requirement>
<requirement key="username">.+</requirement>
</route>
</routes>
Expand All @@ -52,10 +52,10 @@ a more permissive regex path.
use Symfony\Component\Routing\Route;
$collection = new RouteCollection();
$collection->add('_hello', new Route('/hello/{name}', array(
$collection->add('_hello', new Route('/hello/{username}', array(
'_controller' => 'AcmeDemoBundle:Demo:hello',
), array(
'name' => '.+',
'username' => '.+',
)));
return $collection;
Expand All @@ -75,4 +75,4 @@ a more permissive regex path.
}
}
That's it! Now, the ``{name}`` parameter can contain the ``/`` character.
That's it! Now, the ``{username}`` parameter can contain the ``/`` character.

0 comments on commit 188dd1f

Please sign in to comment.