JMSDiExtraBundle
JMSDiExtraBundle copied to clipboard
Inject in action?
Hi, is there a way of injecting services into actions on controller? Injects into __constructor works, but i want to do something like:
class TestController extends Controller
{
/**
* @DI\InjectParams
*/
public function homeAction(Session $session)
{
...
}
}
but i keep get:
Controller "EnhancedProxy_d6771a80f8f76efda9e1b93357e52d63fe73d2a8__CG__\Controller\TestController::homeAction()" requires that you provide a value for the "$session" argument (because there is no default value or because there is a non optional argument after this one).
No it is not. Inject is about configuring the creation of the instance, while the action is called when using the controller, not when creating it.
As @stof said, no, what you're asking for conceptually doesn't make sense, you can define automatic controller injections however, to inject services your ParamConverter's wouldn't derive from the request.
Documentation: http://jmsyst.com/bundles/JMSDiExtraBundle/master/configuration#automatic-controller-injections