@@ -1336,18 +1336,18 @@ A possible solution is to change the parameter requirements to be more permissiv
1336
1336
Route Aliasing
1337
1337
--------------
1338
1338
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 names for the same route
1340
+ and can be used to provide backward compatibility for routes that
1341
+ have been renamed. Let's say you have a route called ``product_show ``:
1342
1342
1343
1343
.. configuration-block ::
1344
1344
1345
1345
.. code-block :: yaml
1346
1346
1347
1347
# config/routes.yaml
1348
- some_route_name :
1349
- path : /some-path
1350
- controller : App\Controller\SomeController::index
1348
+ product_show :
1349
+ path : /product/{id}
1350
+ controller : App\Controller\ProductController::show
1351
1351
1352
1352
.. code-block :: xml
1353
1353
@@ -1358,7 +1358,7 @@ Let's say you have a route called ``some_route_name``
1358
1358
xsi : schemaLocation =" http://symfony.com/schema/routing
1359
1359
https://symfony.com/schema/routing/routing-1.0.xsd" >
1360
1360
1361
- <route id =" some_route_name " path =" /some-path " controller =" App\Controller\SomeController::index " />
1361
+ <route id =" product_show " path =" /product/{id} " controller =" App\Controller\ProductController::show " />
1362
1362
</routes >
1363
1363
1364
1364
.. code-block :: php
@@ -1367,27 +1367,27 @@ Let's say you have a route called ``some_route_name``
1367
1367
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1368
1368
1369
1369
return static function (RoutingConfigurator $routes): void {
1370
- $routes->add('some_route_name ', '/some-path ')
1371
- ->controller('App\Controller\SomeController::index ');
1370
+ $routes->add('product_show ', '/product/{id} ')
1371
+ ->controller('App\Controller\ProductController::show ');
1372
1372
};
1373
1373
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 ``.
1374
+ Now, let's say you want to create a new route called ``product_details ``
1375
+ that acts exactly the same as ``product_show ``.
1376
1376
1377
- Instead of duplicating the original route, you can create an alias for it. You can do this as follows:
1377
+ Instead of duplicating the original route, you can create an alias for it.
1378
1378
1379
1379
.. configuration-block ::
1380
1380
1381
1381
.. code-block :: yaml
1382
1382
1383
1383
# config/routes.yaml
1384
- some_route_name :
1385
- path : /some-path
1386
- controller : App\Controller\SomeController::index
1384
+ product_show :
1385
+ path : /product/{id}
1386
+ controller : App\Controller\ProductController::show
1387
1387
1388
- new_route_name :
1388
+ product_details :
1389
1389
# "alias" option refers to the name of the route declared above
1390
- alias : some_route_name
1390
+ alias : product_show
1391
1391
1392
1392
.. code-block :: xml
1393
1393
@@ -1398,9 +1398,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
1398
1398
xsi : schemaLocation =" http://symfony.com/schema/routing
1399
1399
https://symfony.com/schema/routing/routing-1.0.xsd" >
1400
1400
1401
- <route id =" some_route_name " path =" /some-path " controller =" App\Controller\SomeController::index " />
1401
+ <route id =" product_show " path =" /product/{id} " controller =" App\Controller\ProductController::show " />
1402
1402
<!-- "alias" attribute value refers to the name of the route declared above -->
1403
- <route id =" new_route_name " alias =" some_route_name " />
1403
+ <route id =" product_details " alias =" product_show " />
1404
1404
</routes >
1405
1405
1406
1406
.. code-block :: php
@@ -1409,13 +1409,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
1409
1409
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1410
1410
1411
1411
return static function (RoutingConfigurator $routes): void {
1412
- $routes->add('some_route_name ', '/some_route_path ')
1413
- ->controller('App\Controller\SomeController::index ');
1412
+ $routes->add('product_show ', '/product/{id} ')
1413
+ ->controller('App\Controller\ProductController::show ');
1414
1414
// second argument refers to the name of the route declared above
1415
- $routes->alias('new_route_name ', 'some_route_name ');
1415
+ $routes->alias('product_details ', 'product_show ');
1416
1416
};
1417
1417
1418
- In this example, both ``some_route_name `` and ``new_route_name `` routes can
1418
+ In this example, both ``product_show `` and ``product_details `` routes can
1419
1419
be used in the application and will produce the same result.
1420
1420
1421
1421
.. _routing-alias-deprecation :
@@ -1426,41 +1426,42 @@ Deprecating Route Aliases
1426
1426
Route aliases can be used to provide backward compatibility for routes that
1427
1427
have been renamed.
1428
1428
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.
1429
+ Now, let's say you want to replace the ``product_show `` route in favor of
1430
+ ``product_details `` and mark the old one as deprecated.
1431
1431
1432
- In the previous example, the alias ``new_route_name `` was pointing to
1433
- ``some_route_name `` route.
1432
+ In the previous example, the alias ``product_details `` was pointing to
1433
+ ``product_show `` route.
1434
1434
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:
1435
+ To mark the ``product_show `` route as deprecated, you need to "switch" the alias.
1436
+ The ``product_show `` become the alias, and will now point to the ``product_details `` route.
1437
+ This way, the ``product_show `` alias could be deprecated.
1437
1438
1438
1439
.. configuration-block ::
1439
1440
1440
1441
.. code-block :: yaml
1441
1442
1442
- # Move the concrete route definition under ``new_route_name ``
1443
- new_route_name :
1444
- path : /some-path
1445
- controller : App\Controller\SomeController::index
1443
+ # Move the concrete route definition under ``product_details ``
1444
+ product_details :
1445
+ path : /product/{id}
1446
+ controller : App\Controller\ProductController::show
1446
1447
1447
- # Define the alias and the deprecation under the ``some_route_name `` definition
1448
- some_route_name :
1449
- alias : new_route_name
1448
+ # Define the alias and the deprecation under the ``product_show `` definition
1449
+ product_show :
1450
+ alias : product_details
1450
1451
1451
1452
# 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.
1453
+ # 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.
1453
1454
deprecated :
1454
1455
package : ' acme/package'
1455
1456
version : ' 1.2'
1456
1457
1457
1458
# or
1458
1459
1459
- # you can also define a custom deprecation message (%alias_id% placeholder is available)
1460
+ # you can define a custom deprecation message (%alias_id% placeholder is available)
1460
1461
deprecated :
1461
1462
package : ' acme/package'
1462
1463
version : ' 1.2'
1463
- message : ' The "%alias_id%" route alias is deprecated. Please use "new_route_name " instead.'
1464
+ message : ' The "%alias_id%" route alias is deprecated. Please use "product_details " instead.'
1464
1465
1465
1466
.. code-block :: xml
1466
1467
@@ -1470,46 +1471,46 @@ to be able to mark it as deprecated using the ``deprecated`` option:
1470
1471
xsi : schemaLocation =" http://symfony.com/schema/routing
1471
1472
https://symfony.com/schema/routing/routing-1.0.xsd" >
1472
1473
1473
- <!-- Move the concrete route definition under ``new_route_name `` -->
1474
- <route id =" new_route_name " path =" /some-path " controller =" App\Controller\SomeController::index " />
1474
+ <!-- Move the concrete route definition under ``product_details `` -->
1475
+ <route id =" product_details " path =" /product/{id} " controller =" App\Controller\ProductController::show " />
1475
1476
1476
- <!-- Define the alias and the deprecation under the ``some_route_name `` definition -->
1477
- <route id =" some_route_name " alias =" new_route_name " >
1477
+ <!-- Define the alias and the deprecation under the ``product_show `` definition -->
1478
+ <route id =" product_show " alias =" product_details " >
1478
1479
<!-- 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. -->
1480
+ 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. -->
1480
1481
<deprecated package =" acme/package" version =" 1.2" />
1481
1482
1482
1483
<!-- or -->
1483
1484
1484
- <!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
1485
+ <!-- you can define a custom deprecation message (%alias_id% placeholder is available) -->
1485
1486
<deprecated package =" acme/package" version =" 1.2" >
1486
- The "%alias_id%" route alias is deprecated. Please use "new_route_name " instead.
1487
+ The "%alias_id%" route alias is deprecated. Please use "product_details " instead.
1487
1488
</deprecated >
1488
1489
</route >
1489
1490
</routes >
1490
1491
1491
1492
.. code-block :: php
1492
1493
1493
- $routes->add('new_route_name ', '/some-path ')
1494
- ->controller('App\Controller\SomeController::index ');
1494
+ $routes->add('product_details ', '/product/{id} ')
1495
+ ->controller('App\Controller\ProductController::show ');
1495
1496
1496
- $routes->alias('some_route_name ', 'new_route_name ')
1497
+ $routes->alias('product_show ', 'product_details ')
1497
1498
// 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.
1499
+ // 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.
1499
1500
->deprecate('acme/package', '1.2', '')
1500
1501
1501
1502
// or
1502
1503
1503
- // you can also define a custom deprecation message (%alias_id% placeholder is available)
1504
+ // you can define a custom deprecation message (%alias_id% placeholder is available)
1504
1505
->deprecate(
1505
1506
'acme/package',
1506
1507
'1.2',
1507
- 'The "%alias_id%" route alias is deprecated. Please use "new_route_name " instead.'
1508
+ 'The "%alias_id%" route alias is deprecated. Please use "product_details " instead.'
1508
1509
)
1509
1510
;
1510
1511
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 ``.
1512
+ In this example, every time the ``product_show `` alias is used, a deprecation
1513
+ warning is triggered, advising you to stop using this route and prefer using ``product_details ``.
1513
1514
1514
1515
The message is actually a message template, which replaces occurrences of the
1515
1516
``%alias_id% `` placeholder by the route alias name. You **must ** have
0 commit comments