@@ -1342,6 +1342,23 @@ have been renamed. Let's say you have a route called ``product_show``:
1342
1342
1343
1343
.. configuration-block ::
1344
1344
1345
+ .. code-block :: php-attributes
1346
+
1347
+ // src/Controller/ProductController.php
1348
+ namespace App\Controller;
1349
+
1350
+ use Symfony\Component\HttpFoundation\Response;
1351
+ use Symfony\Component\Routing\Attribute\Route;
1352
+
1353
+ class ProductController
1354
+ {
1355
+ #[Route('/product/{id}', name: 'product_show')]
1356
+ public function show(): Response
1357
+ {
1358
+ // ...
1359
+ }
1360
+ }
1361
+
1345
1362
.. code-block :: yaml
1346
1363
1347
1364
# config/routes.yaml
@@ -1378,6 +1395,25 @@ Instead of duplicating the original route, you can create an alias for it.
1378
1395
1379
1396
.. configuration-block ::
1380
1397
1398
+ .. code-block :: php-attributes
1399
+
1400
+ // src/Controller/ProductController.php
1401
+ namespace App\Controller;
1402
+
1403
+ use Symfony\Component\HttpFoundation\Response;
1404
+ use Symfony\Component\Routing\Attribute\Route;
1405
+
1406
+ class ProductController
1407
+ {
1408
+ // "alias" named argument indicates the name of the alias you want to create.
1409
+ // The alias will point to the actual route "product_show"
1410
+ #[Route('/product/{id}', name: 'product_show', alias: ['product_details'])]
1411
+ public function show(): Response
1412
+ {
1413
+ // ...
1414
+ }
1415
+ }
1416
+
1381
1417
.. code-block :: yaml
1382
1418
1383
1419
# config/routes.yaml
@@ -1418,6 +1454,15 @@ Instead of duplicating the original route, you can create an alias for it.
1418
1454
In this example, both ``product_show `` and ``product_details `` routes can
1419
1455
be used in the application and will produce the same result.
1420
1456
1457
+ .. note ::
1458
+
1459
+ Using non-attributes formats (YAML, XML and PHP) is the only way
1460
+ to define an alias pointing to a route that you don't own.
1461
+
1462
+ So that you can use your own route name for URL generation,
1463
+ while actually using a route defined by a third-party bundle as the target of that URL generation,
1464
+ as the 2 definitions are not required to be in the same config file (or even in the same format).
1465
+
1421
1466
.. _routing-alias-deprecation :
1422
1467
1423
1468
Deprecating Route Aliases
@@ -1438,6 +1483,42 @@ This way, the ``product_show`` alias could be deprecated.
1438
1483
1439
1484
.. configuration-block ::
1440
1485
1486
+ .. code-block :: php-attributes
1487
+
1488
+ // src/Controller/ProductController.php
1489
+ namespace App\Controller;
1490
+
1491
+ use Symfony\Component\HttpFoundation\Response;
1492
+ use Symfony\Component\Routing\Attribute\Route;
1493
+
1494
+ class ProductController
1495
+ {
1496
+ // this outputs the following generic deprecation message:
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.
1498
+ #[Route('/product/{id}',
1499
+ name: 'product_details',
1500
+ alias: new DeprecatedAlias(
1501
+ aliasName: 'product_show',
1502
+ package: 'acme/package',
1503
+ version: '1.2',
1504
+ ),
1505
+ )]
1506
+ // Or, you can also define a custom deprecation message (%alias_id% placeholder is available)
1507
+ #[Route('/product/{id}',
1508
+ name: 'product_details',
1509
+ alias: new DeprecatedAlias(
1510
+ aliasName: 'product_show',
1511
+ package: 'acme/package',
1512
+ version: '1.2',
1513
+ message: 'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.',
1514
+ ),
1515
+ )]
1516
+ public function show(): Response
1517
+ {
1518
+ // ...
1519
+ }
1520
+ }
1521
+
1441
1522
.. code-block :: yaml
1442
1523
1443
1524
# Move the concrete route definition under ``product_details``
0 commit comments