Skip to content

Commit 35bff3a

Browse files
committed
fix(routing): Rename Route Alias route examples
1 parent 34b59df commit 35bff3a

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

routing.rst

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,18 +1336,19 @@ A possible solution is to change the parameter requirements to be more permissiv
13361336
Route Aliasing
13371337
--------------
13381338

1339-
Route alias allow you to have multiple name for the same route:
1340-
1341-
Let's say you have a route called ``some_route_name``
1339+
Route alias allows you to have multiple name for the same route
1340+
and can be used to provide backward compatibility for routes that
1341+
have been renamed.
1342+
Let's say you have a route called ``product_show``
13421343

13431344
.. configuration-block::
13441345

13451346
.. code-block:: yaml
13461347
13471348
# config/routes.yaml
1348-
some_route_name:
1349-
path: /some-path
1350-
controller: App\Controller\SomeController::index
1349+
product_show:
1350+
path: /product/{id}
1351+
controller: App\Controller\ProductController::show
13511352
13521353
.. code-block:: xml
13531354
@@ -1358,7 +1359,7 @@ Let's say you have a route called ``some_route_name``
13581359
xsi:schemaLocation="http://symfony.com/schema/routing
13591360
https://symfony.com/schema/routing/routing-1.0.xsd">
13601361
1361-
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1362+
<route id="product_show" path="/product/{id}" controller="App\Controller\ProductController::show"/>
13621363
</routes>
13631364
13641365
.. code-block:: php
@@ -1367,27 +1368,27 @@ Let's say you have a route called ``some_route_name``
13671368
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
13681369
13691370
return static function (RoutingConfigurator $routes): void {
1370-
$routes->add('some_route_name', '/some-path')
1371-
->controller('App\Controller\SomeController::index');
1371+
$routes->add('product_show', '/product/{id}')
1372+
->controller('App\Controller\ProductController::show');
13721373
};
13731374
1374-
Now, let's say you want to create a new route called ``new_route_name``
1375-
that acts exactly the same as ``some_route_name``.
1375+
Now, let's say you want to create a new route called ``product_details``
1376+
that acts exactly the same as ``product_show``.
13761377

1377-
Instead of duplicating the original route, you can create an alias for it. You can do this as follows:
1378+
Instead of duplicating the original route, you can create an alias for it.
13781379

13791380
.. configuration-block::
13801381

13811382
.. code-block:: yaml
13821383
13831384
# config/routes.yaml
1384-
some_route_name:
1385-
path: /some-path
1386-
controller: App\Controller\SomeController::index
1385+
product_show:
1386+
path: /product/{id}
1387+
controller: App\Controller\ProductController::show
13871388
1388-
new_route_name:
1389+
product_details:
13891390
# "alias" option refers to the name of the route declared above
1390-
alias: some_route_name
1391+
alias: product_show
13911392
13921393
.. code-block:: xml
13931394
@@ -1398,9 +1399,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
13981399
xsi:schemaLocation="http://symfony.com/schema/routing
13991400
https://symfony.com/schema/routing/routing-1.0.xsd">
14001401
1401-
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1402+
<route id="product_show" path="/product/{id}" controller="App\Controller\ProductController::show"/>
14021403
<!-- "alias" attribute value refers to the name of the route declared above -->
1403-
<route id="new_route_name" alias="some_route_name"/>
1404+
<route id="product_details" alias="product_show"/>
14041405
</routes>
14051406
14061407
.. code-block:: php
@@ -1409,13 +1410,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
14091410
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
14101411
14111412
return static function (RoutingConfigurator $routes): void {
1412-
$routes->add('some_route_name', '/some_route_path')
1413-
->controller('App\Controller\SomeController::index');
1413+
$routes->add('product_show', '/product/{id}')
1414+
->controller('App\Controller\ProductController::show');
14141415
// second argument refers to the name of the route declared above
1415-
$routes->alias('new_route_name', 'some_route_name');
1416+
$routes->alias('product_details', 'product_show');
14161417
};
14171418
1418-
In this example, both ``some_route_name`` and ``new_route_name`` routes can
1419+
In this example, both ``product_show`` and ``product_details`` routes can
14191420
be used in the application and will produce the same result.
14201421

14211422
.. _routing-alias-deprecation:
@@ -1426,41 +1427,42 @@ Deprecating Route Aliases
14261427
Route aliases can be used to provide backward compatibility for routes that
14271428
have been renamed.
14281429

1429-
Now, let's say you want to replace the ``some_route_name`` route in favor of
1430-
``new_route_name`` and mark the old one as deprecated.
1430+
Now, let's say you want to replace the ``product_show`` route in favor of
1431+
``product_details`` and mark the old one as deprecated.
14311432

1432-
In the previous example, the alias ``new_route_name`` was pointing to
1433-
``some_route_name`` route.
1433+
In the previous example, the alias ``product_details`` was pointing to
1434+
``product_show`` route.
14341435

1435-
As you want to deprecate the ``some_route_name`` route, so let's invert the alias as follows
1436-
to be able to mark it as deprecated using the ``deprecated`` option:
1436+
To mark the ``product_show`` route as deprecated, you need to "switch" the alias.
1437+
The ``product_show`` become the alias, and will now point to the ``product_details`` route.
1438+
This way, the ``product_show`` alias could be deprecated.
14371439

14381440
.. configuration-block::
14391441

14401442
.. code-block:: yaml
14411443
1442-
# Move the concrete route definition under ``new_route_name``
1443-
new_route_name:
1444-
path: /some-path
1445-
controller: App\Controller\SomeController::index
1444+
# Move the concrete route definition under ``product_details``
1445+
product_details:
1446+
path: /product/{id}
1447+
controller: App\Controller\ProductController::show
14461448
1447-
# Define the alias and the deprecation under the ``some_route_name`` definition
1448-
some_route_name:
1449-
alias: new_route_name
1449+
# Define the alias and the deprecation under the ``product_show`` definition
1450+
product_show:
1451+
alias: product_details
14501452
14511453
# this outputs the following generic deprecation message:
1452-
# Since acme/package 1.2: The "some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1454+
# Since acme/package 1.2: The "product_show" route alias is deprecated. You should stop using it, as it will be removed in the future.
14531455
deprecated:
14541456
package: 'acme/package'
14551457
version: '1.2'
14561458
14571459
# or
14581460
1459-
# you can also define a custom deprecation message (%alias_id% placeholder is available)
1461+
# you can define a custom deprecation message (%alias_id% placeholder is available)
14601462
deprecated:
14611463
package: 'acme/package'
14621464
version: '1.2'
1463-
message: 'The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.'
1465+
message: 'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.'
14641466
14651467
.. code-block:: xml
14661468
@@ -1470,46 +1472,46 @@ to be able to mark it as deprecated using the ``deprecated`` option:
14701472
xsi:schemaLocation="http://symfony.com/schema/routing
14711473
https://symfony.com/schema/routing/routing-1.0.xsd">
14721474
1473-
<!-- Move the concrete route definition under ``new_route_name`` -->
1474-
<route id="new_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1475+
<!-- Move the concrete route definition under ``product_details`` -->
1476+
<route id="product_details" path="/product/{id}" controller="App\Controller\ProductController::show"/>
14751477
1476-
<!-- Define the alias and the deprecation under the ``some_route_name`` definition -->
1477-
<route id="some_route_name" alias="new_route_name">
1478+
<!-- Define the alias and the deprecation under the ``product_show`` definition -->
1479+
<route id="product_show" alias="product_details">
14781480
<!-- this outputs the following generic deprecation message:
1479-
Since acme/package 1.2: The "some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future. -->
1481+
Since acme/package 1.2: The "product_show" route alias is deprecated. You should stop using it, as it will be removed in the future. -->
14801482
<deprecated package="acme/package" version="1.2"/>
14811483
14821484
<!-- or -->
14831485
1484-
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
1486+
<!-- you can define a custom deprecation message (%alias_id% placeholder is available) -->
14851487
<deprecated package="acme/package" version="1.2">
1486-
The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.
1488+
The "%alias_id%" route alias is deprecated. Please use "product_details" instead.
14871489
</deprecated>
14881490
</route>
14891491
</routes>
14901492
14911493
.. code-block:: php
14921494
1493-
$routes->add('new_route_name', '/some-path')
1494-
->controller('App\Controller\SomeController::index');
1495+
$routes->add('product_details', '/product/{id}')
1496+
->controller('App\Controller\ProductController::show');
14951497
1496-
$routes->alias('some_route_name', 'new_route_name')
1498+
$routes->alias('product_show', 'product_details')
14971499
// this outputs the following generic deprecation message:
1498-
// Since acme/package 1.2: The "some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1500+
// Since acme/package 1.2: The "product_show" route alias is deprecated. You should stop using it, as it will be removed in the future.
14991501
->deprecate('acme/package', '1.2', '')
15001502
15011503
// or
15021504
1503-
// you can also define a custom deprecation message (%alias_id% placeholder is available)
1505+
// you can define a custom deprecation message (%alias_id% placeholder is available)
15041506
->deprecate(
15051507
'acme/package',
15061508
'1.2',
1507-
'The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.'
1509+
'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.'
15081510
)
15091511
;
15101512
1511-
In this example, every time the ``some_route_name`` alias is used, a deprecation
1512-
warning is triggered, advising you to stop using this route and prefer using ``new_route_name``.
1513+
In this example, every time the ``product_show`` alias is used, a deprecation
1514+
warning is triggered, advising you to stop using this route and prefer using ``product_details``.
15131515

15141516
The message is actually a message template, which replaces occurrences of the
15151517
``%alias_id%`` placeholder by the route alias name. You **must** have

0 commit comments

Comments
 (0)