I have seen the request object being passed to the controller action method as a parameter like this:
public function addAddressAction(Request $request)
{
If you take a deeper look at the Symfony2 Base Controller code, you may notice that getRequest()
is marked as deprecated since version 2.4 and will be removed in 3.0.
/*
* ...
* @deprecated Deprecated since version 2.4, to be removed in 3.0. Ask
* Symfony to inject the Request object into your controller
* method instead by type hinting it in the method's signature.
*/
public function getRequest()
{
return $this->container->get('request_stack')->getCurrentRequest();
}
Introduced by the following evolution,
And, here's the upgrade from 2.x to 3.0 documentation.
Conclusion,
Your Request should then be part of your action's signature.