Skip to content

Commit d245b45

Browse files
author
Jules Pietri
committed
Fixed route examples
1 parent b9ab0b5 commit d245b45

17 files changed

+118
-121
lines changed

components/routing.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ routes with UTF-8 characters:
422422
xsi:schemaLocation="http://symfony.com/schema/routing
423423
http://symfony.com/schema/routing/routing-1.0.xsd">
424424
425-
<route id="route1" path="/category/{name}">
426-
<default key="_controller">App\Controller\DefaultController::category</default>
425+
<route id="route1" path="/category/{name}" controller="App\Controller\DefaultController::category">
427426
<option key="utf8">true</option>
428427
</route>
429428
</routes>
@@ -498,8 +497,8 @@ You can also include UTF-8 strings as routing requirements:
498497
xsi:schemaLocation="http://symfony.com/schema/routing
499498
http://symfony.com/schema/routing/routing-1.0.xsd">
500499
501-
<route id="route2" path="/default/{default}">
502-
<default key="_controller">App\Controller\DefaultController::default</default>
500+
<route id="route2" path="/default/{default}"
501+
controller="App\Controller\DefaultController::default">
503502
<requirement key="default">한국어</requirement>
504503
<option key="utf8">true</option>
505504
</route>

controller/service.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ a service like: ``App\Controller\HelloController::index``:
3232
class HelloController
3333
{
3434
/**
35-
* @Route("/hello", name="hello")
35+
* @Route("/hello", name="hello", methods={"GET"})
3636
*/
3737
public function index()
3838
{
@@ -45,7 +45,8 @@ a service like: ``App\Controller\HelloController::index``:
4545
# config/routes.yaml
4646
hello:
4747
path: /hello
48-
defaults: { _controller: App\Controller\HelloController::index }
48+
controller: App\Controller\HelloController::index
49+
methods: GET
4950
5051
.. code-block:: xml
5152
@@ -56,9 +57,7 @@ a service like: ``App\Controller\HelloController::index``:
5657
xsi:schemaLocation="http://symfony.com/schema/routing
5758
http://symfony.com/schema/routing/routing-1.0.xsd">
5859
59-
<route id="hello" path="/hello">
60-
<default key="_controller">App\Controller\HelloController::index</default>
61-
</route>
60+
<route id="hello" path="/hello" controller="App\Controller\HelloController::index" methods="GET" />
6261
6362
</routes>
6463
@@ -67,7 +66,7 @@ a service like: ``App\Controller\HelloController::index``:
6766
// config/routes.php
6867
$collection->add('hello', new Route('/hello', [
6968
'_controller' => 'App\Controller\HelloController::index',
70-
]));
69+
], [], [], '', [], ['GET']));
7170
7271
.. _controller-service-invoke:
7372

routing.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,21 @@ Now you can configure the routes:
9090
xsi:schemaLocation="http://symfony.com/schema/routing
9191
http://symfony.com/schema/routing/routing-1.0.xsd">
9292
93-
<route id="blog_list" controller="App\Controller\BlogController::list" path="/blog" >
93+
<route id="blog_list" path="/blog" controller="App\Controller\BlogController::list">
9494
<!-- settings -->
9595
</route>
9696
97-
<route id="blog_show" controller="App\Controller\BlogController::show" path="/blog/{slug}">
97+
<route id="blog_show" path="/blog/{slug}" controller="App\Controller\BlogController::show">
9898
<!-- settings -->
9999
</route>
100100
</routes>
101101
102102
.. code-block:: php
103103
104104
// config/routes.php
105+
use App\Controller\BlogController;
105106
use Symfony\Component\Routing\RouteCollection;
106107
use Symfony\Component\Routing\Route;
107-
use App\Controller\BlogController;
108108
109109
$routes = new RouteCollection();
110110
$routes->add('blog_list', new Route('/blog', [
@@ -407,8 +407,7 @@ concise, but it can decrease route readability when requirements are complex:
407407
xsi:schemaLocation="http://symfony.com/schema/routing
408408
http://symfony.com/schema/routing/routing-1.0.xsd">
409409
410-
<route id="blog_list" path="/blog/{page<\d+>}"
411-
controller="App\Controller\BlogController::list" />
410+
<route id="blog_list" path="/blog/{page<\d+>}" controller="App\Controller\BlogController::list" />
412411
413412
<!-- ... -->
414413
</routes>
@@ -572,8 +571,7 @@ placeholder:
572571
xsi:schemaLocation="http://symfony.com/schema/routing
573572
http://symfony.com/schema/routing/routing-1.0.xsd">
574573
575-
<route id="blog_list" path="/blog/{page <\d+>?1}"
576-
controller="App\Controller\BlogController::list" />
574+
<route id="blog_list" path="/blog/{page <\d+>?1}" controller="App\Controller\BlogController::list" />
577575
578576
<!-- ... -->
579577
</routes>

routing/conditions.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ define arbitrary matching logic, use the ``conditions`` routing option:
5555
xsi:schemaLocation="http://symfony.com/schema/routing
5656
http://symfony.com/schema/routing/routing-1.0.xsd">
5757
58-
<route id="contact" path="/contact">
59-
<default key="_controller">App\Controller\DefaultController::contact</default>
58+
<route id="contact"
59+
path="/contact"
60+
controller="App\Controller\DefaultController::contact">
6061
<condition>context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'</condition>
6162
<!-- expressions can also include config parameters -->
6263
<!-- <condition>request.headers.get('User-Agent') matches '%app.allowed_browsers%'</condition> -->

routing/extra_information.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ to your controller, and as attributes of the ``Request`` object:
3030
xsi:schemaLocation="http://symfony.com/schema/routing
3131
http://symfony.com/schema/routing/routing-1.0.xsd">
3232
33-
<route id="blog" path="/blog/{page}">
34-
<default key="_controller">App\Controller\BlogController::index</default>
33+
<route id="blog"
34+
path="/blog/{page}"
35+
controller="App\Controller\BlogController::index">
3536
<default key="page">1</default>
3637
<default key="title">Hello world!</default>
3738
</route>

routing/hostname_pattern.rst

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ You can also match on the HTTP *host* of the incoming request.
5656
xsi:schemaLocation="http://symfony.com/schema/routing
5757
http://symfony.com/schema/routing/routing-1.0.xsd">
5858
59-
<route id="mobile_homepage" path="/" host="m.example.com">
60-
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
61-
</route>
59+
<route id="mobile_homepage"
60+
path="/"
61+
host="m.example.com"
62+
controller="App\Controller\MainController::mobileHomepage" />
6263
63-
<route id="homepage" path="/">
64-
<default key="_controller">App\Controller\MainController::homepage</default>
65-
</route>
64+
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
6665
</routes>
6766
6867
.. code-block:: php
@@ -104,9 +103,9 @@ you can use placeholders in your hostname:
104103
class MainController extends AbstractController
105104
{
106105
/**
107-
* @Route("/", name="projects_homepage", host="{project_name}.example.com")
106+
* @Route("/", name="projects_homepage", host="{project}.example.com")
108107
*/
109-
public function projectsHomepage()
108+
public function projectsHomepage(string $project)
110109
{
111110
// ...
112111
}
@@ -125,7 +124,7 @@ you can use placeholders in your hostname:
125124
# config/routes.yaml
126125
projects_homepage:
127126
path: /
128-
host: "{project_name}.example.com"
127+
host: "{project}.example.com"
129128
controller: App\Controller\MainController::projectsHomepage
130129
131130
homepage:
@@ -141,13 +140,12 @@ you can use placeholders in your hostname:
141140
xsi:schemaLocation="http://symfony.com/schema/routing
142141
http://symfony.com/schema/routing/routing-1.0.xsd">
143142
144-
<route id="projects_homepage" path="/" host="{project_name}.example.com">
145-
<default key="_controller">App\Controller\MainController::projectsHomepage</default>
146-
</route>
143+
<route id="projects_homepage"
144+
path="/"
145+
host="{project}.example.com"
146+
controller="App\Controller\MainController::projectsHomepage" />
147147
148-
<route id="homepage" path="/">
149-
<default key="_controller">App\Controller\MainController::homepage</default>
150-
</route>
148+
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
151149
</routes>
152150
153151
.. code-block:: php
@@ -159,7 +157,7 @@ you can use placeholders in your hostname:
159157
$routes = new RouteCollection();
160158
$routes->add('project_homepage', new Route('/', [
161159
'_controller' => 'App\Controller\MainController::projectsHomepage',
162-
], [], [], '{project_name}.example.com'));
160+
], [], [], '{project}.example.com'));
163161
164162
$routes->add('homepage', new Route('/', [
165163
'_controller' => 'App\Controller\MainController::homepage',
@@ -231,15 +229,15 @@ instance, if you want to match both ``m.example.com`` and
231229
xsi:schemaLocation="http://symfony.com/schema/routing
232230
http://symfony.com/schema/routing/routing-1.0.xsd">
233231
234-
<route id="mobile_homepage" path="/" host="{subdomain}.example.com">
235-
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
232+
<route id="mobile_homepage"
233+
path="/"
234+
host="{subdomain}.example.com"
235+
controller="App\Controller\MainController::mobileHomepage">
236236
<default key="subdomain">m</default>
237237
<requirement key="subdomain">m|mobile</requirement>
238238
</route>
239239
240-
<route id="homepage" path="/">
241-
<default key="_controller">App\Controller\MainController::homepage</default>
242-
</route>
240+
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
243241
</routes>
244242
245243
.. code-block:: php
@@ -327,15 +325,15 @@ instance, if you want to match both ``m.example.com`` and
327325
xsi:schemaLocation="http://symfony.com/schema/routing
328326
http://symfony.com/schema/routing/routing-1.0.xsd">
329327
330-
<route id="mobile_homepage" path="/" host="m.{domain}">
331-
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
328+
<route id="mobile_homepage"
329+
path="/"
330+
host="m.{domain}"
331+
controller="App\Controller\MainController::mobileHomepage">
332332
<default key="domain">%domain%</default>
333333
<requirement key="domain">%domain%</requirement>
334334
</route>
335335
336-
<route id="homepage" path="/">
337-
<default key="_controller">App\Controller\MainController::homepage</default>
338-
</route>
336+
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
339337
</routes>
340338
341339
.. code-block:: php
@@ -376,7 +374,7 @@ You can also set the host option on imported routes:
376374
.. code-block:: php-annotations
377375
378376
// src/Controller/MainController.php
379-
namespace App\Controller;
377+
namespace Acme\HelloBundle\Controller;
380378
381379
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
382380
use Symfony\Component\Routing\Annotation\Route;
@@ -393,7 +391,7 @@ You can also set the host option on imported routes:
393391
394392
# config/routes.yaml
395393
app_hello:
396-
resource: '@ThirdPartyBundle/Resources/config/routing.yaml'
394+
resource: '@AcmeHelloBundle/Resources/config/routing.yaml'
397395
host: "hello.example.com"
398396
399397
.. code-block:: xml
@@ -405,13 +403,13 @@ You can also set the host option on imported routes:
405403
xsi:schemaLocation="http://symfony.com/schema/routing
406404
http://symfony.com/schema/routing/routing-1.0.xsd">
407405
408-
<import resource="@ThirdPartyBundle/Resources/config/routing.xml" host="hello.example.com" />
406+
<import resource="@AcmeHelloBundle/Resources/config/routing.xml" host="hello.example.com" />
409407
</routes>
410408
411409
.. code-block:: php
412410
413411
// config/routes.php
414-
$routes = $loader->import("@ThirdPartyBundle/Resources/config/routing.php");
412+
$routes = $loader->import("@AcmeHelloBundle/Resources/config/routing.php");
415413
$routes->setHost('hello.example.com');
416414
417415
return $routes;

routing/optional_placeholders.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ the available blog posts for this imaginary blog application:
4343
xsi:schemaLocation="http://symfony.com/schema/routing
4444
http://symfony.com/schema/routing/routing-1.0.xsd">
4545
46-
<route id="blog" path="/blog">
47-
<default key="_controller">App\Controller\BlogController::index</default>
48-
</route>
46+
<route id="blog" path="/blog" controller="App\Controller\BlogController::index" />
4947
</routes>
5048
5149
.. code-block:: php
@@ -98,9 +96,7 @@ entries? Update the route to have a new ``{page}`` placeholder:
9896
xsi:schemaLocation="http://symfony.com/schema/routing
9997
http://symfony.com/schema/routing/routing-1.0.xsd">
10098
101-
<route id="blog" path="/blog/{page}">
102-
<default key="_controller">App\Controller\BlogController::index</default>
103-
</route>
99+
<route id="blog" path="/blog/{page}" controller="App\Controller\BlogController::index" />
104100
</routes>
105101
106102
.. code-block:: php
@@ -159,8 +155,7 @@ This is done by including it in the ``defaults`` collection:
159155
xsi:schemaLocation="http://symfony.com/schema/routing
160156
http://symfony.com/schema/routing/routing-1.0.xsd">
161157
162-
<route id="blog" path="/blog/{page}">
163-
<default key="_controller">App\Controller\BlogController::index</default>
158+
<route id="blog" path="/blog/{page}" controller="App\Controller\BlogController::index">
164159
<default key="page">1</default>
165160
</route>
166161
</routes>

routing/redirect_in_config.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ action to redirect to this new url:
2828
2929
# load some routes - one should ultimately have the path "/app"
3030
controllers:
31-
resource: ../src/Controller/
31+
resource: '../src/Controller/'
3232
type: annotation
3333
prefix: /app
3434
@@ -50,14 +50,12 @@ action to redirect to this new url:
5050
http://symfony.com/schema/routing/routing-1.0.xsd">
5151
5252
<!-- load some routes - one should ultimately have the path "/app" -->
53-
<import resource="../src/Controller/"
54-
type="annotation"
55-
prefix="/app"
56-
/>
53+
<import resource="../src/Controller/" type="annotation" prefix="/app" />
5754
5855
<!-- redirecting the homepage -->
59-
<route id="homepage" path="/">
60-
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
56+
<route id="homepage"
57+
path="/"
58+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
6159
<default key="path">/app</default>
6260
<default key="permanent">true</default>
6361
</route>
@@ -129,8 +127,9 @@ action:
129127
130128
<!-- ... -->
131129
132-
<route id="admin" path="/wp-admin">
133-
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction</default>
130+
<route id="admin"
131+
path="/wp-admin"
132+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction">
134133
<default key="route">sonata_admin_dashboard</default>
135134
<!-- make a permanent redirection... -->
136135
<default key="permanent">true</default>
@@ -218,17 +217,19 @@ permanent redirects use ``308`` code instead of ``301``:
218217
http://symfony.com/schema/routing/routing-1.0.xsd">
219218
220219
<!-- redirects with the 308 status code -->
221-
<route id="route_foo" path="...">
220+
<route id="route_foo"
221+
path="..."
222+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
222223
<!-- ... -->
223-
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
224224
<default key="permanent">true</default>
225225
<default key="keepRequestMethod">true</default>
226226
</route>
227227
228228
<!-- redirects with the 307 status code -->
229-
<route id="route_bar" path="...">
229+
<route id="route_bar"
230+
path="..."
231+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
230232
<!-- ... -->
231-
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
232233
<default key="permanent">false</default>
233234
<default key="keepRequestMethod">true</default>
234235
</route>

0 commit comments

Comments
 (0)