Skip to content

Commit 7410fcc

Browse files
[Routing] Add FQCN and FQCN::method aliases when applicable
1 parent 3c9ddd6 commit 7410fcc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

routing.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,34 @@ For that reason each route has an internal name that must be unique in the
22362236
application. If you don't set the route name explicitly with the ``name``
22372237
option, Symfony generates an automatic name based on the controller and action.
22382238

2239+
Symfony declares aliases based on the FQCN if the target class has an
2240+
``__invoke()`` method that adds a route **and** if the target class added
2241+
one route exactly. Symfony also automatically adds a alias for every method
2242+
that defines only one route. This means that for the following class::
2243+
2244+
// src/Controller/MainController.php
2245+
namespace App\Controller;
2246+
2247+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2248+
use Symfony\Component\Routing\Annotation\Route;
2249+
2250+
class MainController extends AbstractController
2251+
{
2252+
#[Route('/', name: 'homepage', stateless: true)]
2253+
public function homepage(): Response
2254+
{
2255+
// ...
2256+
}
2257+
}
2258+
2259+
An alias named ``App\Controller\MainController::homepage`` will be declared in
2260+
the router.
2261+
2262+
.. versionadded:: 6.4
2263+
2264+
The automatic declaration of aliases based on FQCNs was introduced in
2265+
Symfony 6.4.
2266+
22392267
Generating URLs in Controllers
22402268
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22412269

0 commit comments

Comments
 (0)