Skip to content

Commit dc5d8f8

Browse files
committed
minor #4760 Update routing.rst (ifdattic)
This PR was merged into the 2.3 branch. Discussion ---------- Update routing.rst | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | Commits ------- ddf0bc9 Update routing.rst
2 parents d8e8d75 + ddf0bc9 commit dc5d8f8

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

book/routing.rst

+29-14
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ file:
177177
<container xmlns="http://symfony.com/schema/dic/services"
178178
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
179179
xmlns:framework="http://symfony.com/schema/dic/symfony"
180-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
181-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
180+
xsi:schemaLocation="http://symfony.com/schema/dic/services
181+
http://symfony.com/schema/dic/services/services-1.0.xsd
182+
http://symfony.com/schema/dic/symfony
183+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
182184
183185
<framework:config>
184186
<!-- ... -->
@@ -652,7 +654,9 @@ requirements can easily be added for each parameter. For example:
652654
// ...
653655
654656
/**
655-
* @Route("/blog/{page}", defaults={"page": 1}, requirements={"page": "\d+"})
657+
* @Route("/blog/{page}", defaults={"page": 1}, requirements={
658+
* "page": "\d+"
659+
* })
656660
*/
657661
public function indexAction($page)
658662
{
@@ -740,7 +744,9 @@ URL:
740744
class MainController extends Controller
741745
{
742746
/**
743-
* @Route("/{_locale}", defaults={"_locale": "en"}, requirements={"_locale": "en|fr"})
747+
* @Route("/{_locale}", defaults={"_locale": "en"}, requirements={
748+
* "_locale": "en|fr"
749+
* })
744750
*/
745751
public function homepageAction($_locale)
746752
{
@@ -939,8 +945,12 @@ routing system can be:
939945
/**
940946
* @Route(
941947
* "/articles/{_locale}/{year}/{title}.{_format}",
942-
* defaults: {"_format": "html"}
943-
* requirements: {"_locale": "en|fr", "_format": "html|rss", "year": "\d+"}
948+
* defaults: {"_format": "html"},
949+
* requirements: {
950+
* "_locale": "en|fr",
951+
* "_format": "html|rss",
952+
* "year": "\d+"
953+
* }
944954
* )
945955
*/
946956
public function showAction($_locale, $year, $title)
@@ -1017,7 +1027,7 @@ a slash. URLs matching this route might look like:
10171027
This example also highlights the special ``_format`` routing parameter.
10181028
When using this parameter, the matched value becomes the "request format"
10191029
of the ``Request`` object. Ultimately, the request format is used for such
1020-
things such as setting the ``Content-Type`` of the response (e.g. a ``json``
1030+
things as setting the ``Content-Type`` of the response (e.g. a ``json``
10211031
request format translates into a ``Content-Type`` of ``application/json``).
10221032
It can also be used in the controller to render a different template for
10231033
each value of ``_format``. The ``_format`` parameter is a very powerful way
@@ -1109,7 +1119,7 @@ each is made available as an argument to the controller method::
11091119

11101120
public function showAction($slug)
11111121
{
1112-
// ...
1122+
// ...
11131123
}
11141124

11151125
In reality, the entire ``defaults`` collection is merged with the parameter
@@ -1184,8 +1194,8 @@ configuration:
11841194
11851195
$collection = new RouteCollection();
11861196
$collection->addCollection(
1187-
// second argument is the type, which is required to enable the annotation reader
1188-
// for this resource
1197+
// second argument is the type, which is required to enable
1198+
// the annotation reader for this resource
11891199
$loader->import("@AppBundle/Controller/", "annotation")
11901200
);
11911201
@@ -1275,7 +1285,7 @@ suppose you want to prefix all routes in the AppBundle with ``/site`` (e.g.
12751285
// app/config/routing.php
12761286
use Symfony\Component\Routing\RouteCollection;
12771287
1278-
$app = $loader->import('@AppBundle/Controller/');
1288+
$app = $loader->import('@AppBundle/Controller/', 'annotation');
12791289
$app->addPrefix('/site');
12801290
12811291
$collection = new RouteCollection();
@@ -1361,7 +1371,9 @@ system. Take the ``blog_show`` example route from earlier::
13611371
// '_controller' => 'AppBundle:Blog:show',
13621372
// )
13631373

1364-
$uri = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
1374+
$uri = $this->get('router')->generate('blog_show', array(
1375+
'slug' => 'my-blog-post'
1376+
));
13651377
// /blog/my-blog-post
13661378

13671379
To generate a URL, you need to specify the name of the route (e.g. ``blog_show``)
@@ -1429,7 +1441,10 @@ Generating URLs with Query Strings
14291441
The ``generate`` method takes an array of wildcard values to generate the URI.
14301442
But if you pass extra ones, they will be added to the URI as a query string::
14311443

1432-
$this->get('router')->generate('blog', array('page' => 2, 'category' => 'Symfony'));
1444+
$this->get('router')->generate('blog', array(
1445+
'page' => 2,
1446+
'category' => 'Symfony'
1447+
));
14331448
// /blog/2?category=Symfony
14341449

14351450
Generating URLs from a Template
@@ -1470,7 +1485,7 @@ method::
14701485

14711486
From a template, in Twig, simply use the ``url()`` function (which generates an absolute URL)
14721487
rather than the ``path()`` function (which generates a relative URL). In PHP, pass ``true``
1473-
to ``generateUrl()``:
1488+
to ``generate()``:
14741489

14751490
.. configuration-block::
14761491

0 commit comments

Comments
 (0)