@@ -1336,18 +1336,17 @@ 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 allow you to have multiple name for the same route.
1340
+ Let's say you have a route called ``product_show ``
1342
1341
1343
1342
.. configuration-block ::
1344
1343
1345
1344
.. code-block :: yaml
1346
1345
1347
1346
# 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
1351
1350
1352
1351
.. code-block :: xml
1353
1352
@@ -1358,7 +1357,7 @@ Let's say you have a route called ``some_route_name``
1358
1357
xsi : schemaLocation =" http://symfony.com/schema/routing
1359
1358
https://symfony.com/schema/routing/routing-1.0.xsd" >
1360
1359
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 " />
1362
1361
</routes >
1363
1362
1364
1363
.. code-block :: php
@@ -1367,12 +1366,12 @@ Let's say you have a route called ``some_route_name``
1367
1366
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1368
1367
1369
1368
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 ');
1372
1371
};
1373
1372
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 ``.
1376
1375
1377
1376
Instead of duplicating the original route, you can create an alias for it. You can do this as follows:
1378
1377
@@ -1381,13 +1380,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
1381
1380
.. code-block :: yaml
1382
1381
1383
1382
# config/routes.yaml
1384
- some_route_name :
1383
+ product_show :
1385
1384
path : /some-path
1386
- controller : App\Controller\SomeController::index
1385
+ controller : App\Controller\ProductController::show
1387
1386
1388
- new_route_name :
1387
+ product_details :
1389
1388
# "alias" option refers to the name of the route declared above
1390
- alias : some_route_name
1389
+ alias : product_show
1391
1390
1392
1391
.. code-block :: xml
1393
1392
@@ -1398,9 +1397,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
1398
1397
xsi : schemaLocation =" http://symfony.com/schema/routing
1399
1398
https://symfony.com/schema/routing/routing-1.0.xsd" >
1400
1399
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 " />
1402
1401
<!-- "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 " />
1404
1403
</routes >
1405
1404
1406
1405
.. code-block :: php
@@ -1409,13 +1408,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
1409
1408
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1410
1409
1411
1410
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 ');
1414
1413
// 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 ');
1416
1415
};
1417
1416
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
1419
1418
be used in the application and will produce the same result.
1420
1419
1421
1420
.. _routing-alias-deprecation :
@@ -1426,30 +1425,30 @@ Deprecating Route Aliases
1426
1425
Route aliases can be used to provide backward compatibility for routes that
1427
1426
have been renamed.
1428
1427
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.
1431
1430
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.
1434
1433
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
1436
1435
to be able to mark it as deprecated using the ``deprecated `` option:
1437
1436
1438
1437
.. configuration-block ::
1439
1438
1440
1439
.. code-block :: yaml
1441
1440
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
1446
1445
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
1450
1449
1451
1450
# 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.
1453
1452
deprecated :
1454
1453
package : ' acme/package'
1455
1454
version : ' 1.2'
@@ -1460,7 +1459,7 @@ to be able to mark it as deprecated using the ``deprecated`` option:
1460
1459
deprecated :
1461
1460
package : ' acme/package'
1462
1461
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.'
1464
1463
1465
1464
.. code-block :: xml
1466
1465
@@ -1470,32 +1469,32 @@ to be able to mark it as deprecated using the ``deprecated`` option:
1470
1469
xsi : schemaLocation =" http://symfony.com/schema/routing
1471
1470
https://symfony.com/schema/routing/routing-1.0.xsd" >
1472
1471
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 " />
1475
1474
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 " >
1478
1477
<!-- 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. -->
1480
1479
<deprecated package =" acme/package" version =" 1.2" />
1481
1480
1482
1481
<!-- or -->
1483
1482
1484
1483
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
1485
1484
<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.
1487
1486
</deprecated >
1488
1487
</route >
1489
1488
</routes >
1490
1489
1491
1490
.. code-block :: php
1492
1491
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 ');
1495
1494
1496
- $routes->alias('some_route_name ', 'new_route_name ')
1495
+ $routes->alias('product_show ', 'product_details ')
1497
1496
// 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.
1499
1498
->deprecate('acme/package', '1.2', '')
1500
1499
1501
1500
// or
@@ -1504,12 +1503,12 @@ to be able to mark it as deprecated using the ``deprecated`` option:
1504
1503
->deprecate(
1505
1504
'acme/package',
1506
1505
'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.'
1508
1507
)
1509
1508
;
1510
1509
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 ``.
1513
1512
1514
1513
The message is actually a message template, which replaces occurrences of the
1515
1514
``%alias_id% `` placeholder by the route alias name. You **must ** have
0 commit comments