From e310fb62b397a37fe574f0071b226d675d6cc53b Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Sat, 7 Apr 2012 10:30:17 +0300 Subject: [PATCH] Added Unicode information about routes --- book/routing.rst | 26 +++++++++++++--------- components/routing.rst | 49 +++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index d36066c2365..64982fbd7e2 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -18,7 +18,7 @@ areas of your application. By the end of this chapter, you'll be able to: * Create complex routes that map to controllers * Generate URLs inside templates and controllers -* Load routing resources from bundles (or anywhere else) +* Load routing resources from bundles (or anywhere else) * Debug your routes .. index:: @@ -80,7 +80,7 @@ pattern that points to a specific PHP class and method: .. code-block:: php // src/Acme/BlogBundle/Controller/BlogController.php - + namespace Acme\BlogBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -89,7 +89,7 @@ pattern that points to a specific PHP class and method: public function showAction($slug) { $blog = // use the $slug varible to query the database - + return $this->render('AcmeBlogBundle:Blog:show.html.twig', array( 'blog' => $blog, )); @@ -102,7 +102,13 @@ will be executed and the ``$slug`` variable will be equal to ``my-post``. This is the goal of the Symfony2 router: to map the URL of a request to a controller. Along the way, you'll learn all sorts of tricks that make mapping -even the most complex URLs easy. +even the most complex URLs easy. + +.. tip:: + + As of Symfony 2.1, the Routing component also accepts Unicode values + in routes like: /Жени/ + .. index:: single: Routing; Under the hood @@ -820,10 +826,10 @@ The controller might look like this: .. code-block:: php // src/Acme/BlogBundle/Controller/BlogController.php - + namespace Acme\BlogBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - + class BlogController extends Controller { public function showAction($slug) @@ -1093,9 +1099,9 @@ In an upcoming section, you'll learn how to generate URLs from inside templates. If the frontend of your application uses AJAX requests, you might want to be able to generate URLs in JavaScript based on your routing configuration. By using the `FOSJsRoutingBundle`_, you can do exactly that: - + .. code-block:: javascript - + var url = Routing.generate('blog_show', { "slug": 'my-blog-post}); For more information, see the documentation for that bundle. @@ -1122,9 +1128,9 @@ method: on server information supplied by PHP. When generating absolute URLs for scripts run from the command line, you'll need to manually set the desired host on the ``Request`` object: - + .. code-block:: php - + $request->headers->set('HOST', 'www.example.com'); .. index:: diff --git a/components/routing.rst b/components/routing.rst index 4c9f0243d08..def32c05799 100644 --- a/components/routing.rst +++ b/components/routing.rst @@ -5,7 +5,7 @@ The Routing Component ===================== - The Routing Component maps an HTTP request to a set of configuration + The Routing Component maps an HTTP request to a set of configuration variables. Installation @@ -41,7 +41,7 @@ your autoloader to load the Routing component:: $matcher = new UrlMatcher($routes, $context); - $parameters = $matcher->match( '/foo' ); + $parameters = $matcher->match( '/foo' ); // array('controller' => 'MyController', '_route' => 'route_name') .. note:: @@ -51,7 +51,7 @@ your autoloader to load the Routing component:: matching. An easy way to solve this is to use the HTTPFoundation component as explained :ref:`below`. -You can add as many routes as you like to a +You can add as many routes as you like to a :class:`Symfony\\Component\\Routing\\RouteCollection`. The :method:`RouteCollection::add()` @@ -61,7 +61,7 @@ URL path and some array of custom variables in its constructor. This array of custom variables can be *anything* that's significant to your application, and is returned when that route is matched. -If no matching route can be found a +If no matching route can be found a :class:`Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException` will be thrown. In addition to your array of custom variables, a ``_route`` key is added, @@ -106,11 +106,11 @@ In this case, the route is matched by ``/archive/2012-01``, because the ``{month wildcard matches the regular expression wildcard given. However, ``/archive/foo`` does *not* match, because "foo" fails the month wildcard. -Besides the regular expression constraints there are two special requirements +Besides the regular expression constraints there are two special requirements you can define: * ``_method`` enforces a certain HTTP request method (``HEAD``, ``GET``, ``POST``, ...) -* ``_scheme`` enforces a certain HTTP scheme (``http``, ``https``) +* ``_scheme`` enforces a certain HTTP scheme (``http``, ``https``) For example, the following route would only accept requests to /foo with the POST method and a secure connection:: @@ -118,17 +118,17 @@ the POST method and a secure connection:: $route = new Route('/foo', array('_method' => 'post', '_scheme' => 'https' )); .. tip:: - + If you want to match all urls which start with a certain path and end in an arbitrary suffix you can use the following route definition:: - + $route = new Route('/start/{suffix}', array('suffix' => ''), array('suffix' => '.*')); - + Using Prefixes ~~~~~~~~~~~~~~ -You can add routes or other instances of +You can add routes or other instances of :class:`Symfony\\Component\\Routing\\RouteCollection` to *another* collection. This way you can build a tree of routes. Additionally you can define a prefix, default requirements and default options to all routes of a subtree:: @@ -144,7 +144,7 @@ default requirements and default options to all routes of a subtree:: Set the Request Parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~ -The :class:`Symfony\\Component\\Routing\\RequestContext` provides information +The :class:`Symfony\\Component\\Routing\\RequestContext` provides information about the current request. You can define all parameters of an HTTP request with this class via its constructor:: @@ -152,10 +152,10 @@ with this class via its constructor:: .. _components-routing-http-foundation: -Normally you can pass the values from the ``$_SERVER`` variable to populate the +Normally you can pass the values from the ``$_SERVER`` variable to populate the :class:`Symfony\\Component\\Routing\\RequestContext`. But If you use the -:doc:`HttpFoundation` component, you can use its -:class:`Symfony\\Component\\HttpFoundation\\Request` class to feed the +:doc:`HttpFoundation` component, you can use its +:class:`Symfony\\Component\\HttpFoundation\\Request` class to feed the :class:`Symfony\\Component\\Routing\\RequestContext` in a shortcut:: use Symfony\Component\HttpFoundation\Request; @@ -250,7 +250,7 @@ have to provide the name of a php file which returns a :class:`Symfony\\Componen Routes as Closures .................. -There is also the :class:`Symfony\\Component\\Routing\\Loader\\ClosureLoader`, which +There is also the :class:`Symfony\\Component\\Routing\\Loader\\ClosureLoader`, which calls a closure and uses the result as a :class:`Symfony\\Component\\Routing\\RouteCollection`:: use Symfony\Component\Routing\Loader\ClosureLoader; @@ -280,9 +280,9 @@ a path to the main route definition and some other settings:: public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array()); -With the ``cache_dir`` option you can enable route caching (if you provide a -path) or disable caching (if it's set to ``null``). The caching is done -automatically in the background if you want to use it. A basic example of the +With the ``cache_dir`` option you can enable route caching (if you provide a +path) or disable caching (if it's set to ``null``). The caching is done +automatically in the background if you want to use it. A basic example of the :class:`Symfony\\Component\\Routing\\Router` class would look like:: $locator = new FileLocator(array(__DIR__)); @@ -298,6 +298,15 @@ automatically in the background if you want to use it. A basic example of the .. note:: - If you use caching, the Routing component will compile new classes which - are saved in the ``cache_dir``. This means your script must have write + If you use caching, the Routing component will compile new classes which + are saved in the ``cache_dir``. This means your script must have write permissions for that location. + + +.. tip:: + + As of Symfony 2.1, the Routing component also accepts Unicode values + in routes like this:: + + $routes->add('unicode_route', new Route('/Жени')); +