Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbafc22e

Browse files
committed
fix(routing): Rename Route Alias route examples
1 parent34b59df commitbafc22e

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

‎routing.rst

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,18 +1336,18 @@ A possible solution is to change the parameter requirements to be more permissiv
13361336
Route Aliasing
13371337
--------------
13381338

1339-
Route aliasallow you to have multiplename for the same route:
1340-
1341-
Let's say you have a route called ``some_route_name``
1339+
Route aliasallows you to have multiplenames 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``:
13421342

13431343
..configuration-block::
13441344

13451345
..code-block::yaml
13461346
13471347
# 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
13511351
13521352
..code-block::xml
13531353
@@ -1358,7 +1358,7 @@ Let's say you have a route called ``some_route_name``
13581358
xsi:schemaLocation="http://symfony.com/schema/routing
13591359
https://symfony.com/schema/routing/routing-1.0.xsd">
13601360
1361-
<routeid="some_route_name"path="/some-path"controller="App\Controller\SomeController::index"/>
1361+
<routeid="product_show"path="/product/{id}"controller="App\Controller\ProductController::show"/>
13621362
</routes>
13631363
13641364
..code-block::php
@@ -1367,27 +1367,27 @@ Let's say you have a route called ``some_route_name``
13671367
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
13681368
13691369
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');
13721372
};
13731373
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``.
13761376

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.
13781378

13791379
..configuration-block::
13801380

13811381
..code-block::yaml
13821382
13831383
# 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
13871387
1388-
new_route_name:
1388+
product_details:
13891389
# "alias" option refers to the name of the route declared above
1390-
alias:some_route_name
1390+
alias:product_show
13911391
13921392
..code-block::xml
13931393
@@ -1398,9 +1398,9 @@ Instead of duplicating the original route, you can create an alias for it. You c
13981398
xsi:schemaLocation="http://symfony.com/schema/routing
13991399
https://symfony.com/schema/routing/routing-1.0.xsd">
14001400
1401-
<routeid="some_route_name"path="/some-path"controller="App\Controller\SomeController::index"/>
1401+
<routeid="product_show"path="/product/{id}"controller="App\Controller\ProductController::show"/>
14021402
<!-- "alias" attribute value refers to the name of the route declared above-->
1403-
<routeid="new_route_name"alias="some_route_name"/>
1403+
<routeid="product_details"alias="product_show"/>
14041404
</routes>
14051405
14061406
..code-block::php
@@ -1409,13 +1409,13 @@ Instead of duplicating the original route, you can create an alias for it. You c
14091409
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
14101410
14111411
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');
14141414
// 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');
14161416
};
14171417
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
14191419
be used in the application and will produce the same result.
14201420

14211421
.. _routing-alias-deprecation:
@@ -1426,41 +1426,42 @@ Deprecating Route Aliases
14261426
Route aliases can be used to provide backward compatibility for routes that
14271427
have been renamed.
14281428

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.
14311431

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.
14341434

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.
14371438

14381439
..configuration-block::
14391440

14401441
..code-block::yaml
14411442
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
14461447
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
14501451
14511452
# 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.
14531454
deprecated:
14541455
package:'acme/package'
14551456
version:'1.2'
14561457
14571458
# or
14581459
1459-
# you canalsodefine a custom deprecation message (%alias_id% placeholder is available)
1460+
# you can define a custom deprecation message (%alias_id% placeholder is available)
14601461
deprecated:
14611462
package:'acme/package'
14621463
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.'
14641465
14651466
..code-block::xml
14661467
@@ -1470,46 +1471,46 @@ to be able to mark it as deprecated using the ``deprecated`` option:
14701471
xsi:schemaLocation="http://symfony.com/schema/routing
14711472
https://symfony.com/schema/routing/routing-1.0.xsd">
14721473
1473-
<!-- Move the concrete route definition under ``new_route_name``-->
1474-
<routeid="new_route_name"path="/some-path"controller="App\Controller\SomeController::index"/>
1474+
<!-- Move the concrete route definition under ``product_details``-->
1475+
<routeid="product_details"path="/product/{id}"controller="App\Controller\ProductController::show"/>
14751476
1476-
<!-- Define the alias and the deprecation under the ``some_route_name`` definition-->
1477-
<routeid="some_route_name"alias="new_route_name">
1477+
<!-- Define the alias and the deprecation under the ``product_show`` definition-->
1478+
<routeid="product_show"alias="product_details">
14781479
<!-- 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.-->
14801481
<deprecatedpackage="acme/package"version="1.2"/>
14811482
14821483
<!-- or-->
14831484
1484-
<!-- you canalsodefine a custom deprecation message (%alias_id% placeholder is available)-->
1485+
<!-- you can define a custom deprecation message (%alias_id% placeholder is available)-->
14851486
<deprecatedpackage="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.
14871488
</deprecated>
14881489
</route>
14891490
</routes>
14901491
14911492
..code-block::php
14921493
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');
14951496
1496-
$routes->alias('some_route_name', 'new_route_name')
1497+
$routes->alias('product_show', 'product_details')
14971498
// 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.
14991500
->deprecate('acme/package', '1.2', '')
15001501
15011502
// or
15021503
1503-
// you canalsodefine a custom deprecation message (%alias_id% placeholder is available)
1504+
// you can define a custom deprecation message (%alias_id% placeholder is available)
15041505
->deprecate(
15051506
'acme/package',
15061507
'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.'
15081509
)
15091510
;
15101511
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``.
15131514

15141515
The message is actually a message template, which replaces occurrences of the
15151516
``%alias_id%`` placeholder by the route alias name. You **must** have

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp