JMSDiExtraBundle icon indicating copy to clipboard operation
JMSDiExtraBundle copied to clipboard

Inject in action?

Open dewos opened this issue 12 years ago • 2 comments
trafficstars

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).

dewos avatar Mar 31 '13 04:03 dewos

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.

stof avatar Apr 06 '13 00:04 stof

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

stevelacey avatar Apr 25 '13 14:04 stevelacey