Skip to content

Commit 9418739

Browse files
committed
fix(route-alias): Clarify route aliases examples with explicit route names
1 parent d232ccc commit 9418739

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

routing.rst

+31-13
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,12 @@ Route alias allow you to have multiple name for the same route:
13431343
.. code-block:: yaml
13441344
13451345
# config/routes.yaml
1346-
new_route_name:
1347-
alias: original_route_name
1346+
some_route_name:
1347+
path: /some-path
1348+
controller: App\Controller\SomeController::index
1349+
1350+
alias_to_some_route_name:
1351+
alias: some_route_name # refers to the name of the route declared above
13481352
13491353
.. code-block:: xml
13501354
@@ -1355,7 +1359,9 @@ Route alias allow you to have multiple name for the same route:
13551359
xsi:schemaLocation="http://symfony.com/schema/routing
13561360
https://symfony.com/schema/routing/routing-1.0.xsd">
13571361
1358-
<route id="new_route_name" alias="original_route_name"/>
1362+
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1363+
<!-- "alias" attribute value refers to the name of the route declared above -->
1364+
<route id="alias_to_some_route_name" alias="some_route_name"/>
13591365
</routes>
13601366
13611367
.. code-block:: php
@@ -1364,10 +1370,13 @@ Route alias allow you to have multiple name for the same route:
13641370
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
13651371
13661372
return static function (RoutingConfigurator $routes): void {
1367-
$routes->alias('new_route_name', 'original_route_name');
1373+
$routes->add('some_route_name', '/some_route_path')
1374+
->controller('App\Controller\SomeController::index');
1375+
// second argument refers to the name of the route declared above
1376+
$routes->alias('alias_to_some_route_name', 'some_route_name');
13681377
};
13691378
1370-
In this example, both ``original_route_name`` and ``new_route_name`` routes can
1379+
In this example, both ``some_route_name`` and ``alias_to_some_route_name`` routes can
13711380
be used in the application and will produce the same result.
13721381

13731382
.. _routing-alias-deprecation:
@@ -1382,11 +1391,15 @@ you decided not to maintain it anymore), you can deprecate its definition:
13821391

13831392
.. code-block:: yaml
13841393
1385-
new_route_name:
1386-
alias: original_route_name
1394+
some_route_name:
1395+
path: /some-path
1396+
controller: App\Controller\SomeController::index
1397+
1398+
alias_to_some_route_name:
1399+
alias: some_route_name # refers to the name of the route declared above
13871400
13881401
# this outputs the following generic deprecation message:
1389-
# Since acme/package 1.2: The "new_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1402+
# Since acme/package 1.2: The "alias_to_some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
13901403
deprecated:
13911404
package: 'acme/package'
13921405
version: '1.2'
@@ -1405,9 +1418,11 @@ you decided not to maintain it anymore), you can deprecate its definition:
14051418
xsi:schemaLocation="http://symfony.com/schema/routing
14061419
https://symfony.com/schema/routing/routing-1.0.xsd">
14071420
1408-
<route id="new_route_name" alias="original_route_name">
1421+
<route id="some_route_name" path="/some-path" controller="App\Controller\SomeController::index"/>
1422+
<!-- "alias" attribute value refers to the name of the route declared above -->
1423+
<route id="alias_to_some_route_name" alias="some_route_name">
14091424
<!-- this outputs the following generic deprecation message:
1410-
Since acme/package 1.2: The "new_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future. -->
1425+
Since acme/package 1.2: The "alias_to_some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future. -->
14111426
<deprecated package="acme/package" version="1.2"/>
14121427
14131428
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
@@ -1419,9 +1434,12 @@ you decided not to maintain it anymore), you can deprecate its definition:
14191434
14201435
.. code-block:: php
14211436
1422-
$routes->alias('new_route_name', 'original_route_name')
1437+
$routes->add('some_route_name', '/some_route_path')
1438+
->controller('App\Controller\SomeController::index');
1439+
// second argument refers to the name of the route declared above
1440+
$routes->alias('alias_to_some_route_name', 'some_route_name');
14231441
// this outputs the following generic deprecation message:
1424-
// Since acme/package 1.2: The "new_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1442+
// Since acme/package 1.2: The "alias_to_some_route_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
14251443
->deprecate('acme/package', '1.2', '')
14261444
14271445
// you can also define a custom deprecation message (%alias_id% placeholder is available)
@@ -1432,7 +1450,7 @@ you decided not to maintain it anymore), you can deprecate its definition:
14321450
)
14331451
;
14341452
1435-
In this example, every time the ``new_route_name`` alias is used, a deprecation
1453+
In this example, every time the ``alias_to_some_route_name`` alias is used, a deprecation
14361454
warning is triggered, advising you to stop using that alias.
14371455

14381456
The message is actually a message template, which replaces occurrences of the

0 commit comments

Comments
 (0)