Skip to content

Commit 4363b78

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Routing] Document the new alias feature Add ignoreAttributes to the documentation
2 parents 909c8d7 + cfd203d commit 4363b78

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

routing.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,118 @@ A possible solution is to change the parameter requirements to be more permissiv
14581458
as the token and the format will be empty. This can be solved by replacing
14591459
the ``.+`` requirement by ``[^.]+`` to allow any character except dots.
14601460

1461+
.. _routing-alias:
1462+
1463+
Route Aliasing
1464+
--------------
1465+
1466+
.. versionadded:: 5.4
1467+
1468+
Support for route aliases was introduced in Symfony 5.4.
1469+
1470+
Route alias allow you to have multiple name for the same route:
1471+
1472+
.. configuration-block::
1473+
1474+
.. code-block:: yaml
1475+
1476+
# config/routes.yaml
1477+
new_route_name:
1478+
alias: original_route_name
1479+
1480+
.. code-block:: xml
1481+
1482+
<!-- config/routes.xml -->
1483+
<?xml version="1.0" encoding="UTF-8" ?>
1484+
<routes xmlns="http://symfony.com/schema/routing"
1485+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1486+
xsi:schemaLocation="http://symfony.com/schema/routing
1487+
https://symfony.com/schema/routing/routing-1.0.xsd">
1488+
1489+
<route id="new_route_name" alias="original_route_name"/>
1490+
</routes>
1491+
1492+
.. code-block:: php
1493+
1494+
// config/routes.php
1495+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1496+
1497+
return function (RoutingConfigurator $routes) {
1498+
$routes->alias('new_route_name', 'original_route_name');
1499+
};
1500+
1501+
In this example, both ``original_route_name`` and ``new_route_name`` routes can
1502+
be used in the application and will produce the same result.
1503+
1504+
.. _routing-alias-deprecation:
1505+
1506+
Deprecating Route Aliases
1507+
~~~~~~~~~~~~~~~~~~~~~~~~~
1508+
1509+
If some route alias should no longer be used (because it is outdated or
1510+
you decided not to maintain it anymore), you can deprecate its definition:
1511+
1512+
.. configuration-block::
1513+
1514+
.. code-block:: yaml
1515+
1516+
new_route_name:
1517+
alias: original_route_name
1518+
1519+
# this outputs the following generic deprecation message:
1520+
# 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.
1521+
deprecated:
1522+
package: 'acme/package'
1523+
version: '1.2'
1524+
1525+
# you can also define a custom deprecation message (%alias_id% placeholder is available)
1526+
deprecated:
1527+
package: 'acme/package'
1528+
version: '1.2'
1529+
message: 'The "%alias_id%" route alias is deprecated. Do not use it anymore.'
1530+
1531+
.. code-block:: xml
1532+
1533+
<?xml version="1.0" encoding="UTF-8" ?>
1534+
<routes xmlns="http://symfony.com/schema/routing"
1535+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1536+
xsi:schemaLocation="http://symfony.com/schema/routing
1537+
https://symfony.com/schema/routing/routing-1.0.xsd">
1538+
1539+
<route id="new_route_name" alias="original_route_name">
1540+
<!-- this outputs the following generic deprecation message:
1541+
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. -->
1542+
<deprecated package="acme/package" version="1.2"/>
1543+
1544+
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
1545+
<deprecated package="acme/package" version="1.2">
1546+
The "%alias_id%" route alias is deprecated. Do not use it anymore.
1547+
</deprecated>
1548+
</route>
1549+
</routes>
1550+
1551+
.. code-block:: php
1552+
1553+
$routes->alias('new_route_name', 'original_route_name')
1554+
// this outputs the following generic deprecation message:
1555+
// 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.
1556+
->deprecate('acme/package', '1.2', '')
1557+
1558+
// you can also define a custom deprecation message (%alias_id% placeholder is available)
1559+
->deprecate(
1560+
'acme/package',
1561+
'1.2',
1562+
'The "%alias_id%" route alias is deprecated. Do not use it anymore.'
1563+
)
1564+
;
1565+
1566+
In this example, every time the ``new_route_name`` alias is used, a deprecation
1567+
warning is triggered, advising you to stop using that alias.
1568+
1569+
The message is actually a message template, which replaces occurrences of the
1570+
``%alias_id%`` placeholder by the route alias name. You **must** have
1571+
at least one occurrence of the ``%alias_id%`` placeholder in your template.
1572+
14611573
.. _routing-route-groups:
14621574

14631575
Route Groups and Prefixes
@@ -1758,6 +1870,8 @@ Use the ``RedirectController`` to redirect to other routes and URLs:
17581870
# * for temporary redirects, it uses the 307 status code instead of 302
17591871
# * for permanent redirects, it uses the 308 status code instead of 301
17601872
keepRequestMethod: true
1873+
# add this to remove the original route attributes when redirecting
1874+
ignoreAttributes: true
17611875
17621876
legacy_doc:
17631877
path: /legacy/doc

0 commit comments

Comments
 (0)