Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit590c5cd

Browse files
committed
Merge pull request#1225 from dlsniper/unicode-routes
Added Unicode information about routes
2 parentsbd2e5a1 +e310fb6 commit590c5cd

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

‎book/routing.rst‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ areas of your application. By the end of this chapter, you'll be able to:
1818

1919
* Create complex routes that map to controllers
2020
* Generate URLs inside templates and controllers
21-
* Load routing resources from bundles (or anywhere else)
21+
* Load routing resources from bundles (or anywhere else)
2222
* Debug your routes
2323

2424
..index::
@@ -80,7 +80,7 @@ pattern that points to a specific PHP class and method:
8080
..code-block::php
8181
8282
// src/Acme/BlogBundle/Controller/BlogController.php
83-
83+
8484
namespace Acme\BlogBundle\Controller;
8585
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8686
@@ -89,7 +89,7 @@ pattern that points to a specific PHP class and method:
8989
public function showAction($slug)
9090
{
9191
$blog = // use the $slug varible to query the database
92-
92+
9393
return $this->render('AcmeBlogBundle:Blog:show.html.twig', array(
9494
'blog' => $blog,
9595
));
@@ -102,7 +102,13 @@ will be executed and the ``$slug`` variable will be equal to ``my-post``.
102102

103103
This is the goal of the Symfony2 router: to map the URL of a request to a
104104
controller. Along the way, you'll learn all sorts of tricks that make mapping
105-
even the most complex URLs easy.
105+
even the most complex URLs easy.
106+
107+
..tip::
108+
109+
As of Symfony 2.1, the Routing component also accepts Unicode values
110+
in routes like: /Жени/
111+
106112

107113
..index::
108114
single: Routing; Under the hood
@@ -820,10 +826,10 @@ The controller might look like this:
820826
..code-block::php
821827
822828
// src/Acme/BlogBundle/Controller/BlogController.php
823-
829+
824830
namespace Acme\BlogBundle\Controller;
825831
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
826-
832+
827833
class BlogController extends Controller
828834
{
829835
public function showAction($slug)
@@ -1093,9 +1099,9 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
10931099
If the frontend of your application uses AJAX requests, you might want
10941100
to be able to generate URLs in JavaScript based on your routing configuration.
10951101
By using the `FOSJsRoutingBundle`_, you can do exactly that:
1096-
1102+
10971103
..code-block::javascript
1098-
1104+
10991105
var url=Routing.generate('blog_show', {"slug":'my-blog-post});
11001106
11011107
For more information, see the documentation for that bundle.
@@ -1122,9 +1128,9 @@ method:
11221128
on server information supplied byPHP.When generating absolute URLsfor
11231129
scripts run from the command line, you'll need to manually set the desired
11241130
host on the ``Request`` object:
1125-
1131+
11261132
.. code-block:: php
1127-
1133+
11281134
$request->headers->set('HOST','www.example.com');
11291135
11301136
.. index::

‎components/routing.rst‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The Routing Component
66
=====================
77

8-
The Routing Component maps an HTTP request to a set of configuration
8+
The Routing Component maps an HTTP request to a set of configuration
99
variables.
1010

1111
Installation
@@ -41,7 +41,7 @@ your autoloader to load the Routing component::
4141

4242
$matcher = new UrlMatcher($routes, $context);
4343

44-
$parameters = $matcher->match( '/foo' );
44+
$parameters = $matcher->match( '/foo' );
4545
// array('controller' => 'MyController', '_route' => 'route_name')
4646

4747
..note::
@@ -51,7 +51,7 @@ your autoloader to load the Routing component::
5151
matching. An easy way to solve this is to use the HTTPFoundation component
5252
as explained:ref:`below<components-routing-http-foundation>`.
5353

54-
You can add as many routes as you like to a
54+
You can add as many routes as you like to a
5555
:class:`Symfony\\Component\\Routing\\RouteCollection`.
5656

5757
The:method:`RouteCollection::add()<Symfony\\Component\\Routing\\RouteCollection::add>`
@@ -61,7 +61,7 @@ URL path and some array of custom variables in its constructor. This array
6161
of custom variables can be *anything* that's significant to your application,
6262
and is returned when that route is matched.
6363

64-
If no matching route can be found a
64+
If no matching route can be found a
6565
:class:`Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException` will be thrown.
6666

6767
In addition to your array of custom variables, a ``_route`` key is added,
@@ -106,29 +106,29 @@ In this case, the route is matched by ``/archive/2012-01``, because the ``{month
106106
wildcard matches the regular expression wildcard given. However, ``/archive/foo``
107107
does *not* match, because "foo" fails the month wildcard.
108108

109-
Besides the regular expression constraints there are two special requirements
109+
Besides the regular expression constraints there are two special requirements
110110
you can define:
111111

112112
* ``_method`` enforces a certain HTTP request method (``HEAD``, ``GET``, ``POST``, ...)
113-
* ``_scheme`` enforces a certain HTTP scheme (``http``, ``https``)
113+
* ``_scheme`` enforces a certain HTTP scheme (``http``, ``https``)
114114

115115
For example, the following route would only accept requests to /foo with
116116
the POST method and a secure connection::
117117

118118
$route = new Route('/foo', array('_method' => 'post', '_scheme' => 'https' ));
119119

120120
..tip::
121-
121+
122122
If you want to match all urls which start with a certain path and end in an
123123
arbitrary suffix you can use the following route definition::
124-
124+
125125
$route = new Route('/start/{suffix}', array('suffix' => ''), array('suffix' => '.*'));
126-
126+
127127

128128
Using Prefixes
129129
~~~~~~~~~~~~~~
130130

131-
You can add routes or other instances of
131+
You can add routes or other instances of
132132
:class:`Symfony\\Component\\Routing\\RouteCollection` to *another* collection.
133133
This way you can build a tree of routes. Additionally you can define a prefix,
134134
default requirements and default options to all routes of a subtree::
@@ -144,18 +144,18 @@ default requirements and default options to all routes of a subtree::
144144
Set the Request Parameters
145145
~~~~~~~~~~~~~~~~~~~~~~~~~~
146146

147-
The:class:`Symfony\\Component\\Routing\\RequestContext` provides information
147+
The:class:`Symfony\\Component\\Routing\\RequestContext` provides information
148148
about the current request. You can define all parameters of an HTTP request
149149
with this class via its constructor::
150150

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

153153
.. _components-routing-http-foundation:
154154

155-
Normally you can pass the values from the ``$_SERVER`` variable to populate the
155+
Normally you can pass the values from the ``$_SERVER`` variable to populate the
156156
:class:`Symfony\\Component\\Routing\\RequestContext`. But If you use the
157-
:doc:`HttpFoundation<http_foundation>` component, you can use its
158-
:class:`Symfony\\Component\\HttpFoundation\\Request` class to feed the
157+
:doc:`HttpFoundation<http_foundation>` component, you can use its
158+
:class:`Symfony\\Component\\HttpFoundation\\Request` class to feed the
159159
:class:`Symfony\\Component\\Routing\\RequestContext` in a shortcut::
160160

161161
use Symfony\Component\HttpFoundation\Request;
@@ -250,7 +250,7 @@ have to provide the name of a php file which returns a :class:`Symfony\\Componen
250250
Routes as Closures
251251
..................
252252

253-
There is also the:class:`Symfony\\Component\\Routing\\Loader\\ClosureLoader`, which
253+
There is also the:class:`Symfony\\Component\\Routing\\Loader\\ClosureLoader`, which
254254
calls a closure and uses the result as a:class:`Symfony\\Component\\Routing\\RouteCollection`::
255255

256256
use Symfony\Component\Routing\Loader\ClosureLoader;
@@ -280,9 +280,9 @@ a path to the main route definition and some other settings::
280280

281281
public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array());
282282

283-
With the ``cache_dir`` option you can enable route caching (if you provide a
284-
path) or disable caching (if it's set to ``null``). The caching is done
285-
automatically in the background if you want to use it. A basic example of the
283+
With the ``cache_dir`` option you can enable route caching (if you provide a
284+
path) or disable caching (if it's set to ``null``). The caching is done
285+
automatically in the background if you want to use it. A basic example of the
286286
:class:`Symfony\\Component\\Routing\\Router` class would look like::
287287

288288
$locator = new FileLocator(array(__DIR__));
@@ -298,6 +298,15 @@ automatically in the background if you want to use it. A basic example of the
298298

299299
..note::
300300

301-
If you use caching, the Routing component will compile new classes which
302-
are saved in the ``cache_dir``. This means your script must have write
301+
If you use caching, the Routing component will compile new classes which
302+
are saved in the ``cache_dir``. This means your script must have write
303303
permissions for that location.
304+
305+
306+
..tip::
307+
308+
As of Symfony 2.1, the Routing component also accepts Unicode values
309+
in routes like this::
310+
311+
$routes->add('unicode_route', new Route('/Жени'));
312+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp