Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update slash_in_parameter.rst #4307

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.