-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Controller resolver doesn't inject container for invokable controller (no specified method in route) #31271
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
Comments
If your controller is registered as a service, you either need to add the |
But why I meet another behavior for a configured controller in route with Let's make behavior consistent. |
Closing as this is a new feature that has been implemented for consistency in #26085 already |
Beware that auto-injection of the container is also deprecated in #27462. So you define it as a service subscriber, e.g. by setting autoconfigure: true |
Thanks for explanation. |
I cannot avoid the problem with not injected container for invokable controllers, even if I follow docs recommendations (add I create reproduce app with more details here https://github.com/andrew-demb/sf-31271-inject-container-in-invokable-controller. |
Problem can be solved in my side by three ways:
|
In my opinion issue should be reopened, because following docs doesn't clear way to use invokable controllers without investigation about autowire or controller resolver workflow. |
@andrew-demb setting symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveServiceSubscribersPass.php Lines 30 to 32 in 94fd42c
Which docs, that you are talking about, are wrong? |
@Tobion, you won, I cannot prevent adding autowire or manually add method call in DI. Sorry for "falsy"-issue. Reasons weren't clear for me before. References to docs, where I would like to see mentions about required autowire or explicit method call with P. S. Is in the sentence below explained about required container injection? (https://symfony.com/doc/current/service_container/3.3-di-changes.html#step-2-using-class-service-id-s) |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected: 3.4.26
Description
Got fatal
Call to a member function has() on null
due to not injected container (service locator) in controller, extended fromSymfony\Bundle\FrameworkBundle\Controller\AbstractController
.Actual when in route I use DI service id for invokable controller.
How to reproduce
Create controller
Register in services:
Use in route:
Go to
/
path.Possible Solution
Change if statement to work with route without
:
-notation, and not only with array-callables.symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php
Line 45 in 2774705
Workaround for me:
Additional context
The text was updated successfully, but these errors were encountered: