Skip to content

Commit

Permalink
[cookbook][routing] Proofreading the new slash in parameter cookbook …
Browse files Browse the repository at this point in the history
…entry
  • Loading branch information
weaverryan committed Jun 27, 2011
1 parent 6b7cca4 commit d61dc78
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions cookbook/index.rst
Expand Up @@ -8,6 +8,7 @@ Cookbook
controller/service

routing/scheme
routing/slash_in_parameter

assetic/yuicompressor
templating/PHP
Expand Down
1 change: 1 addition & 0 deletions cookbook/map.rst.inc
Expand Up @@ -6,6 +6,7 @@
* **Routing**

* :doc:`/cookbook/routing/scheme`
* :doc:`/cookbook/routing/slash_in_parameter`

* **Templating and Assets**

Expand Down
23 changes: 15 additions & 8 deletions cookbook/routing/slash_in_parameter.rst
@@ -1,20 +1,25 @@
.. index::
single: Routing; Allow / in route parameter

How to allow / character in a route parameter
=============================================
How to allow a "/" character in a route parameter
=================================================

Sometimes, you need to compose URLs with parameters that can contain a slash
``/``. But Symfony uses this character as separator between route parts.
``/``. For example, take the classic ``/hello/{name}`` 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.

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

Configure the Route
-------------------

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

You must explicitely allow ``/`` to be part of your parameter specifying
You must explicitly allow ``/`` to be part of your parameter by specifying
a more permissive regex pattern.

.. configuration-block::
Expand Down Expand Up @@ -55,7 +60,7 @@ a more permissive regex pattern.
return $collection;
.. code-block:: annotation
.. code-block:: php-annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
Expand All @@ -68,4 +73,6 @@ a more permissive regex pattern.
{
// ...
}
}
}
That's it! Now, the ``{name}`` parameter can contain the ``/`` character.

0 comments on commit d61dc78

Please sign in to comment.