-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Allow using invokable controller's FQCN (i.e. ::class
) to generate URLs (instead of route name)
#49981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
This was referenced Apr 8, 2023
I like the idea. However, we currently generate a name for routes already, if the name property is omitted. Silently changing the strategy how that name is generated would be a BC break. |
Not sure I would deprecate the currently generated name, but why not create an alias indeed. |
fabpot
added a commit
that referenced
this issue
Jun 20, 2023
…cable (fancyweb) This PR was merged into the 6.4 branch. Discussion ---------- [Routing] Add FQCN and FQCN::method aliases when applicable | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #49981 | License | MIT | Doc PR | - See #49981, I think it's a great idea 😃 * We add an FQCN alias only if the target class has an `__invoke` method that adds a route AND if the target class added 1 route exactly. * We add a FQCN::method alias for every method that defines only one route. Commits ------- 9fa5bae [Routing] Add FQCN and FQCN::method aliases when applicable
symfony-splitter
pushed a commit
to symfony/routing
that referenced
this issue
Jun 20, 2023
73D7
…cable (fancyweb) This PR was merged into the 6.4 branch. Discussion ---------- [Routing] Add FQCN and FQCN::method aliases when applicable | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | symfony/symfony#49981 | License | MIT | Doc PR | - See symfony/symfony#49981, I think it's a great idea 😃 * We add an FQCN alias only if the target class has an `__invoke` method that adds a route AND if the target class added 1 route exactly. * We add a FQCN::method alias for every method that defines only one route. Commits ------- 9fa5bae407 [Routing] Add FQCN and FQCN::method aliases when applicable
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Description
With the advent of invokable controllers, it would be possible to move away from using names (i.e. strings) as route idenfifiers, and use the controller's FQCN instead:
Then in any service:
Twig:
{{ path('App\\Controller\\SomeController') }}
Advantage: No more strings! :-)
I got the idea from https://tomasvotruba.com/blog/to-route-or-to-action-thats-the-question which says that this is possible in Laravel:
Example
No response
The text was updated successfully, but these errors were encountered: