Skip to content

Commit 6703044

Browse files
committed
minor #11245 Improved routing section (Jules Pietri)
This PR was merged into the 4.2 branch. Discussion ---------- Improved routing section Continuation of #11113 in 4.2. Commits ------- 0054bf5 Improved routing section
2 parents 8b23729 + 0054bf5 commit 6703044

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

components/routing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ In order to set up a basic routing system you need three parts:
3030

3131
* A :class:`Symfony\\Component\\Routing\\RouteCollection`, which contains the route definitions (instances of the class :class:`Symfony\\Component\\Routing\\Route`)
3232
* A :class:`Symfony\\Component\\Routing\\RequestContext`, which has information about the request
33-
* A :class:`Symfony\\Component\\Routing\\Matcher\\UrlMatcher`, which performs the mapping of the request to a single route
33+
* A :class:`Symfony\\Component\\Routing\\Matcher\\UrlMatcher`, which performs the mapping of the path to a single route
3434

3535
Here is a quick example. Notice that this assumes that you've already configured
3636
your autoloader to load the Routing component::
@@ -423,7 +423,7 @@ routes with UTF-8 characters:
423423
.. code-block:: yaml
424424
425425
route1:
426-
path: /category/{name}
426+
path: /category/{name}
427427
controller: App\Controller\DefaultController::category
428428
options:
429429
utf8: true
@@ -492,8 +492,8 @@ You can also include UTF-8 strings as routing requirements:
492492
.. code-block:: yaml
493493
494494
route2:
495-
path: /category/{name}
496-
controller: 'App\Controller\DefaultController::category'
495+
path: /category/{name}
496+
controller: App\Controller\DefaultController::category
497497
defaults:
498498
name: "한국어"
499499
options:

routing.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ route that can match *any* URL like ``/blog/my-post`` or
2727
``/blog/all-about-symfony``.
2828

2929
Routes can be configured in YAML, XML, PHP or annotations. All formats provide
30-
the same features and performance, so choose the one you prefer:
30+
the same features and performance, so choose the one you prefer. If you choose
31+
PHP annotations, run this command once in your application to add support for
32+
them (``SensioFrameworkExtraBundle`` wraps the required dependencies and
33+
provides many useful annotations for cache, security and more!):
34+
35+
.. code-block:: terminal
36+
37+
$ composer require annotations
38+
39+
Now you can configure the routes:
3140

3241
.. configuration-block::
3342

@@ -217,8 +226,12 @@ Symfony provides a handy way to declare localized routes without duplication.
217226
use App\Controller\CompanyController;
218227
219228
return function (RoutingConfigurator $routes) {
220-
$routes->add('about_us', ['nl' => '/over-ons', 'en' => '/about-us'])
221-
->controller([CompanyController::class, 'about']);
229+
$routes->add('about_us', [
230+
'nl' => '/over-ons',
231+
'en' => '/about-us',
232+
])
233+
->controller([CompanyController::class, 'about'])
234+
;
222235
};
223236
224237
When a localized route is matched Symfony automatically knows which locale
@@ -601,7 +614,7 @@ As your app grows, you'll eventually have a *lot* of routes! To see them all, ru
601614
------------------------------ -------- -------------------------------------
602615
Name Method Path
603616
------------------------------ -------- -------------------------------------
604-
app_lucky_number ANY /lucky/number/{max}
617+
app_lucky_number ANY /lucky/number/{max}
605618
...
606619
------------------------------ -------- -------------------------------------
607620

routing/external_resources.rst

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This can be done by importing routing resources from the main routing file:
1919
# config/routes.yaml
2020
app_file:
2121
# loads routes from the given routing file stored in some bundle
22-
resource: '@AcmeOtherBundle/Resources/config/routing.yaml'
22+
resource: '@AcmeBundle/Resources/config/routing.yaml'
2323
2424
app_annotations:
2525
# loads routes from the PHP annotations of the controllers found in that directory
@@ -46,7 +46,7 @@ This can be done by importing routing resources from the main routing file:
4646
https://symfony.com/schema/routing/routing-1.0.xsd">
4747
4848
<!-- loads routes from the given routing file stored in some bundle -->
49-
<import resource="@AcmeOtherBundle/Resources/config/routing.yaml"/>
49+
<import resource="@AcmeBundle/Resources/config/routing.yaml"/>
5050
5151
<!-- loads routes from the PHP annotations of the controllers found in that directory -->
5252
<import resource="../src/Controller/" type="annotation"/>
@@ -65,7 +65,7 @@ This can be done by importing routing resources from the main routing file:
6565
6666
return function (RoutingConfigurator $routes) {
6767
// loads routes from the given routing file stored in some bundle
68-
$routes->import('@AcmeOtherBundle/Resources/config/routing.yaml');
68+
$routes->import('@AcmeBundle/Resources/config/routing.yaml');
6969
7070
// loads routes from the PHP annotations of the controllers found in that directory
7171
$routes->import('../src/Controller/', 'annotation');
@@ -74,7 +74,7 @@ This can be done by importing routing resources from the main routing file:
7474
$routes->import('../legacy/routing/', 'directory');
7575
7676
// loads routes from the YAML or XML files found in some bundle directory
77-
$routes->import('@AcmeOtherBundle/Resources/config/routing/public/', 'directory');
77+
$routes->import('@AcmeOtherBundle/Resources/config/routing/', 'directory');
7878
};
7979
8080
.. note::
@@ -88,8 +88,8 @@ Prefixing the URLs of Imported Routes
8888
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8989

9090
You can also choose to provide a "prefix" for the imported routes. For example,
91-
suppose you want to prefix all application routes with ``/site`` (e.g.
92-
``/site/blog/{slug}`` instead of ``/blog/{slug}``):
91+
to prefix all application routes with ``/site`` (e.g. ``/site/blog/{slug}``
92+
instead of ``/blog/{slug}``):
9393

9494
.. configuration-block::
9595

@@ -166,8 +166,7 @@ be prefixed with the string ``/site``.
166166
xsi:schemaLocation="http://symfony.com/schema/routing
167167
https://symfony.com/schema/routing/routing-1.0.xsd">
168168
169-
<import
170-
resource="../src/Controller/"
169+
<import resource="../src/Controller/"
171170
type="annotation"
172171
prefix="/site"
173172
trailing-slash-on-root="false"/>
@@ -201,7 +200,7 @@ a controller class or imported from a configuration file:
201200
/**
202201
* @Route(name="blog_")
203202
*/
204-
class BlogController extends AbstractController
203+
class BlogController
205204
{
206205
/**
207206
* @Route("/blog", name="index")
@@ -237,8 +236,7 @@ a controller class or imported from a configuration file:
237236
xsi:schemaLocation="http://symfony.com/schema/routing
238237
https://symfony.com/schema/routing/routing-1.0.xsd">
239238
240-
<import
241-
resource="../src/Controller/"
239+
<import resource="../src/Controller/"
242240
type="annotation"
243241
name-prefix="blog_"/>
244242
</routes>

routing/optional_placeholders.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ the available blog posts for this imaginary blog application:
1414
// src/Controller/BlogController.php
1515
use Symfony\Component\Routing\Annotation\Route;
1616
17-
// ...
18-
class BlogController extends AbstractController
17+
class BlogController
1918
{
2019
/**
2120
* @Route("/blog")

0 commit comments

Comments
 (0)