-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
Description
Currently, when a route is defined without a name
, Symfony creates a default name in the form: app_<controller>_<method>
(see AttributeClassLoader::getDefaultRouteName()
)
I'm suggesting to change this to the controller's FQCN: App\Controller\MyController
.
In other words: Change the newly created FQCN alias (introduced in #50084) to be the actual name:
Controller | Current system | New system |
---|---|---|
name: 'foo' |
name: foo alias: App\Controller\MyController |
<= same |
name is not set |
name: app_my__invoke alias: App\Controller\MyController |
name: App\Controller\MyController alias: none |
Reason: Twig!
The idea of #49981 was to get rid of manually creating a name
, and always just use the FQCN. But in Twig
{% if 'App\Controller\MyController' == app.current_route %}
... doesn't work, since app.current_route
is app_my__invoke
.
Although I doubt that many people rely on the current default route (the syntax isn't even documented properly, see https://symfony.com/doc/current/routing.html#generating-urls), changing it would still be a BC break.
As a next step, the docs could be changed to (I could take care of that):
- Give a clear recommendation for invokable controllers.
- Remove the route
name
from most code samples, and explain it as a solution for special cases only.
Example
No response