File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -2236,6 +2236,34 @@ For that reason each route has an internal name that must be unique in the
2236
2236
application. If you don't set the route name explicitly with the ``name ``
2237
2237
option, Symfony generates an automatic name based on the controller and action.
2238
2238
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
+
2239
2267
Generating URLs in Controllers
2240
2268
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2241
2269
You can’t perform that action at this time.
0 commit comments