diff --git a/routing.rst b/routing.rst index d7b86784dbc..408f397652d 100644 --- a/routing.rst +++ b/routing.rst @@ -2236,6 +2236,34 @@ For that reason each route has an internal name that must be unique in the application. If you don't set the route name explicitly with the ``name`` option, Symfony generates an automatic name based on the controller and action. +Symfony declares aliases based on the FQCN if the target class has an +``__invoke()`` method that adds a route **and** if the target class added +one route exactly. Symfony also automatically adds a alias for every method +that defines only one route. This means that for the following class:: + + // src/Controller/MainController.php + namespace App\Controller; + + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Routing\Annotation\Route; + + final class MainController extends AbstractController + { + #[Route('/', name: 'homepage')] + public function homepage(): Response + { + // ... + } + } + +An alias named ``App\Controller\MainController::homepage`` will be declared in +the router. + +.. versionadded:: 6.4 + + The automatic declaration of aliases based on FQCNs was introduced in + Symfony 6.4. + Generating URLs in Controllers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy