Skip to content

[Routing] correct environment-specific routing configuration examples #21279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ given value:
.. code-block:: yaml
# config/routes.yaml
tools:
path: /tools
controller: App\Controller\DefaultController::developerTools
env: dev
when@dev:
tools:
path: /tools
controller: App\Controller\DefaultController::developerTools
.. code-block:: xml
Expand All @@ -296,9 +296,9 @@ given value:
xsi:schemaLocation="http://symfony.com/schema/routing
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="tools" path="/tools" controller="App\Controller\DefaultController::developerTools">
<env>dev</env>
</route>
<when env="dev">
<route id="tools" path="/tools" controller="App\Controller\DefaultController::developerTools"/>
</when>
</routes>
.. code-block:: php
Expand All @@ -308,10 +308,11 @@ given value:
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return function (RoutingConfigurator $routes): void {
$routes->add('tools', '/tools')
->controller([DefaultController::class, 'developerTools'])
->env('dev')
;
if('dev' === $routes->env()) {
$routes->add('tools', '/tools')
->controller([DefaultController::class, 'developerTools'])
;
}
};
.. _routing-matching-expressions:
Expand Down