Skip to content

Commit 8ad67e2

Browse files
committed
Merge branch '4.4'
* 4.4: Added a versionadded directive [DX] Improving redirect config
2 parents 38df107 + 69f11e7 commit 8ad67e2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

routing.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,7 @@ the ``template`` option:
13091309
Redirecting to URLs and Routes
13101310
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13111311

1312-
Use the ``RedirectController`` to redirect to other routes (``redirectAction``)
1313-
and URLs (``urlRedirectAction``):
1312+
Use the ``RedirectController`` to redirect to other routes and URLs:
13141313

13151314
.. configuration-block::
13161315

@@ -1319,7 +1318,7 @@ and URLs (``urlRedirectAction``):
13191318
# config/routes.yaml
13201319
doc_shortcut:
13211320
path: /doc
1322-
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
1321+
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
13231322
defaults:
13241323
route: 'doc_page'
13251324
# optionally you can define some arguments passed to the route
@@ -1336,7 +1335,7 @@ and URLs (``urlRedirectAction``):
13361335
13371336
legacy_doc:
13381337
path: /legacy/doc
1339-
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
1338+
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
13401339
defaults:
13411340
# this value can be an absolute path or an absolute URL
13421341
path: 'https://legacy.example.com/doc'
@@ -1352,7 +1351,7 @@ and URLs (``urlRedirectAction``):
13521351
https://symfony.com/schema/routing/routing-1.0.xsd">
13531352
13541353
<route id="doc_shortcut" path="/doc"
1355-
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction">
1354+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController">
13561355
<default key="route">doc_page</default>
13571356
<!-- optionally you can define some arguments passed to the route -->
13581357
<default key="page">index</default>
@@ -1368,7 +1367,7 @@ and URLs (``urlRedirectAction``):
13681367
</route>
13691368
13701369
<route id="legacy_doc" path="/legacy/doc"
1371-
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
1370+
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController">
13721371
<!-- this value can be an absolute path or an absolute URL -->
13731372
<default key="path">https://legacy.example.com/doc</default>
13741373
<!-- redirections are temporary by default (code 302) but you can make them permanent (code 301)-->
@@ -1385,7 +1384,7 @@ and URLs (``urlRedirectAction``):
13851384
13861385
return function (RoutingConfigurator $routes) {
13871386
$routes->add('doc_shortcut', '/doc')
1388-
->controller([RedirectController::class, 'redirectAction'])
1387+
->controller(RedirectController::class)
13891388
->defaults([
13901389
'route' => 'doc_page',
13911390
// optionally you can define some arguments passed to the template
@@ -1403,7 +1402,7 @@ and URLs (``urlRedirectAction``):
14031402
;
14041403
14051404
$routes->add('legacy_doc', '/legacy/doc')
1406-
->controller([RedirectController::class, 'urlRedirectAction'])
1405+
->controller(RedirectController::class)
14071406
->defaults([
14081407
// this value can be an absolute path or an absolute URL
14091408
'path' => 'https://legacy.example.com/doc',
@@ -1418,6 +1417,13 @@ and URLs (``urlRedirectAction``):
14181417
Symfony also provides some utilities to
14191418
:ref:`redirect inside controllers <controller-redirect>`
14201419

1420+
.. versionadded:: 4.4
1421+
1422+
In Symfony versions prior to 4.4, you needed to define the specific
1423+
``RedirectController`` method to use (either ``redirectAction`` or
1424+
``urlRedirectAction``). Starting from Symfony 4.4 this is no longer needed
1425+
because Symfony detects if the redirection is to a route or an URL.
1426+
14211427
.. _routing-trailing-slash-redirection:
14221428

14231429
Redirecting URLs with Trailing Slashes

0 commit comments

Comments
 (0)