Skip to content

Commit

Permalink
Added Unicode information about routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsniper committed Apr 7, 2012
1 parent 61f74f8 commit e310fb6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
26 changes: 16 additions & 10 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down Expand Up @@ -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;
Expand All @@ -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,
));
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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::
Expand Down
49 changes: 29 additions & 20 deletions components/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::
Expand All @@ -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<components-routing-http-foundation>`.

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()<Symfony\\Component\\Routing\\RouteCollection::add>`
Expand All @@ -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,
Expand Down Expand Up @@ -106,29 +106,29 @@ 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::

$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::
Expand All @@ -144,18 +144,18 @@ 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::

public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443)

.. _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<http_foundation>` component, you can use its
:class:`Symfony\\Component\\HttpFoundation\\Request` class to feed the
:doc:`HttpFoundation<http_foundation>` 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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__));
Expand All @@ -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('/Жени'));

0 comments on commit e310fb6

Please sign in to comment.