@@ -1336,18 +1336,19 @@ 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 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 ``
1342
1343
1343
1344
.. configuration-block ::
1344
1345
1345
1346
.. code-block :: yaml
1346
1347
1347
1348
# 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
1351
1352
1352
1353
.. code-block :: xml
1353
1354
@@ -1358,7 +1359,7 @@ Let's say you have a route called ``some_route_name``
1358
1359
xsi : schemaLocation =" http://symfony.com/schema/routing
1359
1360
https://symfony.com/schema/routing/routing-1.0.xsd" >
1360
1361
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 " />
1362
1363
</routes >
1363
1364
1364
1365
.. code-block :: php
@@ -1367,27 +1368,27 @@ Let's say you have a route called ``some_route_name``
1367
1368
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1368
1369
1369
1370
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 ');
1372
1373
};
1373
1374
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 ``.
1376
1377
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.
1378
1379
1379
1380
.. configuration-block ::
1380
1381
1381
1382
.. code-block :: yaml
1382
1383
1383
1384
# 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
1387
1388
1388
- new_route_name :
1389
+ product_details :
1389
1390
# "alias" option refers to the name of the route declared above
1390
- alias : some_route_name
1391
+ alias : product_show
1391
1392
1392
1393
.. code-block :: xml
1393
1394
@@ -1398,9 +1399,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
1398
1399
xsi : schemaLocation =" http://symfony.com/schema/routing
1399
1400
https://symfony.com/schema/routing/routing-1.0.xsd" >
1400
1401
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 " />
1402
1403
<!-- "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 " />
1404
1405
</routes >
1405
1406
1406
1407
.. code-block :: php
@@ -1409,13 +1410,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
1409
1410
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1410
1411
1411
1412
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 ');
1414
1415
// 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 ');
1416
1417
};
1417
1418
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
1419
1420
be used in the application and will produce the same result.
1420
1421
1421
1422
.. _routing-alias-deprecation :
@@ -1426,41 +1427,42 @@ Deprecating Route Aliases
1426
1427
Route aliases can be used to provide backward compatibility for routes that
1427
1428
have been renamed.
1428
1429
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.
1431
1432
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.
1434
1435
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.
1437
1439
1438
1440
.. configuration-block ::
1439
1441
1440
1442
.. code-block :: yaml
1441
1443
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
1446
1448
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
1450
1452
1451
1453
# 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.
1453
1455
deprecated :
1454
1456
package : ' acme/package'
1455
1457
version : ' 1.2'
1456
1458
1457
1459
# or
1458
1460
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)
1460
1462
deprecated :
1461
1463
package : ' acme/package'
1462
1464
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.'
1464
1466
1465
1467
.. code-block :: xml
1466
1468
@@ -1470,46 +1472,46 @@ to be able to mark it as deprecated using the ``deprecated`` option:
1470
1472
xsi : schemaLocation =" http://symfony.com/schema/routing
1471
1473
https://symfony.com/schema/routing/routing-1.0.xsd" >
1472
1474
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 " />
1475
1477
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 " >
1478
1480
<!-- 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. -->
1480
1482
<deprecated package =" acme/package" version =" 1.2" />
1481
1483
1482
1484
<!-- or -->
1483
1485
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) -->
1485
1487
<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.
1487
1489
</deprecated >
1488
1490
</route >
1489
1491
</routes >
1490
1492
1491
1493
.. code-block :: php
1492
1494
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 ');
1495
1497
1496
- $routes->alias('some_route_name ', 'new_route_name ')
1498
+ $routes->alias('product_show ', 'product_details ')
1497
1499
// 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.
1499
1501
->deprecate('acme/package', '1.2', '')
1500
1502
1501
1503
// or
1502
1504
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)
1504
1506
->deprecate(
1505
1507
'acme/package',
1506
1508
'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.'
1508
1510
)
1509
1511
;
1510
1512
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 ``.
1513
1515
1514
1516
The message is actually a message template, which replaces occurrences of the
1515
1517
``%alias_id% `` placeholder by the route alias name. You **must ** have
0 commit comments