From bead9b351b3673feb0e7e4f50d1199d5c86a2368 Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Thu, 18 Oct 2012 09:18:59 -0400 Subject: [PATCH 1/4] [Routing]Added a note about defining route requirements in the container --- book/routing.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/book/routing.rst b/book/routing.rst index 35d521436b7..ce61457b346 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -612,6 +612,16 @@ the regular expression ``(en|fr)``. | /es | *won't match this route* | +-----+--------------------------+ +.. sidebar:: Requirements defined in the container + + If for some reason you need to define some configurable requirements, + you can use a parameter from the service container. For instance, if you + have a _locale parameter in the routes and you like it to be configurable, + you can do this: requirements: _locale: %locale% + + Then just define in the container a locale parameter. This is quite useful + if you don't want to search all your code only to change a simple requirement. + .. index:: single: Routing; Method requirement From b680cfc2448e38ac5c0990f6f5556d11a81e4c4b Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Thu, 18 Oct 2012 13:17:45 -0400 Subject: [PATCH 2/4] Switch to a section and added a config block --- book/routing.rst | 56 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index ce61457b346..a8e653e463e 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -612,15 +612,57 @@ the regular expression ``(en|fr)``. | /es | *won't match this route* | +-----+--------------------------+ -.. sidebar:: Requirements defined in the container +.. index:: + single: Routing; Requirements service + +Requirements defined in the Service Container +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If for some reason you need to define some configurable requirements, you can +use a parameter from the Service Container. For instance, if you have a +``_locale`` parameter in the routes and you like it to be configurable, +you can do this: + +.. configuration-block:: + + .. code-block:: yaml + + contact: + pattern: /_locale/contact + defaults: { _controller: AcmeDemoBundle:Main:contact } + requirements: + _locale: %locale% + + .. code-block:: xml + + + + - If for some reason you need to define some configurable requirements, - you can use a parameter from the service container. For instance, if you - have a _locale parameter in the routes and you like it to be configurable, - you can do this: requirements: _locale: %locale% + + AcmeDemoBundle:Main:contact + %locale% + + + + .. code-block:: php + + use Symfony\Component\Routing\RouteCollection; + use Symfony\Component\Routing\Route; + + $collection = new RouteCollection(); + $collection->add('contact', new Route('/_locale/contact', array( + '_controller' => 'AcmeDemoBundle:Main:contact', + ), array( + '_locale' => '%locale%', + ))); + + return $collection; - Then just define in the container a locale parameter. This is quite useful - if you don't want to search all your code only to change a simple requirement. +Then just define in the container the locale parameter. This is quite useful +if you don't want to search all your code only to change a simple requirement. .. index:: single: Routing; Method requirement From 77c8a87bc7ffa5f2c14694257871129a2b2e1e33 Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Thu, 18 Oct 2012 14:04:35 -0400 Subject: [PATCH 3/4] Fixed grammar issues --- book/routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/routing.rst b/book/routing.rst index a8e653e463e..d7e8b1dc197 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -618,7 +618,7 @@ the regular expression ``(en|fr)``. Requirements defined in the Service Container ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If for some reason you need to define some configurable requirements, you can +If, for some reason, you need to define some configurable requirements, you can use a parameter from the Service Container. For instance, if you have a ``_locale`` parameter in the routes and you like it to be configurable, you can do this: From 702825e793081de91aa6dcb68abc5ff24f13cf5a Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Fri, 19 Oct 2012 07:24:49 -0400 Subject: [PATCH 4/4] Fixed typo --- book/routing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index d7e8b1dc197..dd18fd3752b 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -628,7 +628,7 @@ you can do this: .. code-block:: yaml contact: - pattern: /_locale/contact + pattern: /{_locale}/contact defaults: { _controller: AcmeDemoBundle:Main:contact } requirements: _locale: %locale% @@ -641,7 +641,7 @@ you can do this: 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"> - + AcmeDemoBundle:Main:contact %locale% @@ -653,7 +653,7 @@ you can do this: use Symfony\Component\Routing\Route; $collection = new RouteCollection(); - $collection->add('contact', new Route('/_locale/contact', array( + $collection->add('contact', new Route('/{_locale}/contact', array( '_controller' => 'AcmeDemoBundle:Main:contact', ), array( '_locale' => '%locale%',