Skip to content

Commit 19ac993

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

File tree

1 file changed

+47
-48
lines changed

1 file changed

+47
-48
lines changed

routing.rst

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,18 +1336,17 @@ 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 allow you to have multiple name for the same route.
1340+
Let's say you have a route called ``product_show``
13421341

13431342
.. configuration-block::
13441343

13451344
.. code-block:: yaml
13461345
13471346
# config/routes.yaml
1348-
some_route_name:
1349-
path: /some-path
1350-
controller: App\Controller\SomeController::index
1347+
product_show:
1348+
path: /product/{id}
1349+
controller: App\Controller\ProductController::show
13511350
13521351
.. code-block:: xml
13531352
@@ -1358,7 +1357,7 @@ Let's say you have a route called ``some_route_name``
13581357
xsi:schemaLocation="http://symfony.com/schema/routing
13591358
https://symfony.com/schema/routing/routing-1.0.xsd">
13601359
1361-
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1360+
<route id="product_show" path="/product/{id}" controller="App\Controller\ProductController::show"/>
13621361
</routes>
13631362
13641363
.. code-block:: php
@@ -1367,12 +1366,12 @@ Let's say you have a route called ``some_route_name``
13671366
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
13681367
13691368
return static function (RoutingConfigurator $routes): void {
1370-
$routes->add('some_route_name', '/some-path')
1371-
->controller('App\Controller\SomeController::index');
1369+
$routes->add('product_show', '/product/{id}')
1370+
->controller('App\Controller\ProductController::show');
13721371
};
13731372
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``.
1373+
Now, let's say you want to create a new route called ``product_details``
1374+
that acts exactly the same as ``product_show``.
13761375

13771376
Instead of duplicating the original route, you can create an alias for it. You can do this as follows:
13781377

@@ -1381,13 +1380,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
13811380
.. code-block:: yaml
13821381
13831382
# config/routes.yaml
1384-
some_route_name:
1383+
product_show:
13851384
path: /some-path
1386-
controller: App\Controller\SomeController::index
1385+
controller: App\Controller\ProductController::show
13871386
1388-
new_route_name:
1387+
product_details:
13891388
# "alias" option refers to the name of the route declared above
1390-
alias: some_route_name
1389+
alias: product_show
13911390
13921391
.. code-block:: xml
13931392
@@ -1398,9 +1397,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
13981397
xsi:schemaLocation="http://symfony.com/schema/routing
13991398
https://symfony.com/schema/routing/routing-1.0.xsd">
14001399
1401-
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1400+
<route id="product_show" path="/product/{id}" controller="App\Controller\ProductController::show"/>
14021401
<!-- "alias" attribute value refers to the name of the route declared above -->
1403-
<route id="new_route_name" alias="some_route_name"/>
1402+
<route id="product_details" alias="product_show"/>
14041403
</routes>
14051404
14061405
.. code-block:: php
@@ -1409,13 +1408,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
14091408
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
14101409
14111410
return static function (RoutingConfigurator $routes): void {
1412-
$routes->add('some_route_name', '/some_route_path')
1413-
->controller('App\Controller\SomeController::index');
1411+
$routes->add('product_show', '/product/{id}')
1412+
->controller('App\Controller\ProductController::show');
14141413
// second argument refers to the name of the route declared above
1415-
$routes->alias('new_route_name', 'some_route_name');
1414+
$routes->alias('product_details', 'product_show');
14161415
};
14171416
1418-
In this example, both ``some_route_name`` and ``new_route_name`` routes can
1417+
In this example, both ``product_show`` and ``product_details`` routes can
14191418
be used in the application and will produce the same result.
14201419

14211420
.. _routing-alias-deprecation:
@@ -1426,30 +1425,30 @@ Deprecating Route Aliases
14261425
Route aliases can be used to provide backward compatibility for routes that
14271426
have been renamed.
14281427

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.
1428+
Now, let's say you want to replace the ``product_show`` route in favor of
1429+
``product_details`` and mark the old one as deprecated.
14311430

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

1435-
As you want to deprecate the ``some_route_name`` route, so let's invert the alias as follows
1434+
As you want to deprecate the ``product_show`` route, so let's invert the alias as follows
14361435
to be able to mark it as deprecated using the ``deprecated`` option:
14371436

14381437
.. configuration-block::
14391438

14401439
.. code-block:: yaml
14411440
1442-
# Move the concrete route definition under ``new_route_name``
1443-
new_route_name:
1444-
path: /some-path
1445-
controller: App\Controller\SomeController::index
1441+
# Move the concrete route definition under ``product_details``
1442+
product_details:
1443+
path: /product/{id}
1444+
controller: App\Controller\ProductController::show
14461445
1447-
# Define the alias and the deprecation under the ``some_route_name`` definition
1448-
some_route_name:
1449-
alias: new_route_name
1446+
# Define the alias and the deprecation under the ``product_show`` definition
1447+
product_show:
1448+
alias: product_details
14501449
14511450
# 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.
1451+
# 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.
14531452
deprecated:
14541453
package: 'acme/package'
14551454
version: '1.2'
@@ -1460,7 +1459,7 @@ to be able to mark it as deprecated using the ``deprecated`` option:
14601459
deprecated:
14611460
package: 'acme/package'
14621461
version: '1.2'
1463-
message: 'The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.'
1462+
message: 'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.'
14641463
14651464
.. code-block:: xml
14661465
@@ -1470,32 +1469,32 @@ to be able to mark it as deprecated using the ``deprecated`` option:
14701469
xsi:schemaLocation="http://symfony.com/schema/routing
14711470
https://symfony.com/schema/routing/routing-1.0.xsd">
14721471
1473-
<!-- Move the concrete route definition under ``new_route_name`` -->
1474-
<route id="new_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1472+
<!-- Move the concrete route definition under ``product_details`` -->
1473+
<route id="product_details" path="/product/{id}" controller="App\Controller\ProductController::show"/>
14751474
1476-
<!-- Define the alias and the deprecation under the ``some_route_name`` definition -->
1477-
<route id="some_route_name" alias="new_route_name">
1475+
<!-- Define the alias and the deprecation under the ``product_show`` definition -->
1476+
<route id="product_show" alias="product_details">
14781477
<!-- 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. -->
1478+
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. -->
14801479
<deprecated package="acme/package" version="1.2"/>
14811480
14821481
<!-- or -->
14831482
14841483
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
14851484
<deprecated package="acme/package" version="1.2">
1486-
The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.
1485+
The "%alias_id%" route alias is deprecated. Please use "product_details" instead.
14871486
</deprecated>
14881487
</route>
14891488
</routes>
14901489
14911490
.. code-block:: php
14921491
1493-
$routes->add('new_route_name', '/some-path')
1494-
->controller('App\Controller\SomeController::index');
1492+
$routes->add('product_details', '/product/{id}')
1493+
->controller('App\Controller\ProductController::show');
14951494
1496-
$routes->alias('some_route_name', 'new_route_name')
1495+
$routes->alias('product_show', 'product_details')
14971496
// 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.
1497+
// 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.
14991498
->deprecate('acme/package', '1.2', '')
15001499
15011500
// or
@@ -1504,12 +1503,12 @@ to be able to mark it as deprecated using the ``deprecated`` option:
15041503
->deprecate(
15051504
'acme/package',
15061505
'1.2',
1507-
'The "%alias_id%" route alias is deprecated. Please use "new_route_name" instead.'
1506+
'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.'
15081507
)
15091508
;
15101509
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``.
1510+
In this example, every time the ``product_show`` alias is used, a deprecation
1511+
warning is triggered, advising you to stop using this route and prefer using ``product_details``.
15131512

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

0 commit comments

Comments
 (0)