I am writing a Symfony 2.6 application and I\'ve encountered a problem when trying to inject the RequestStack into a service. What I want is to be able to get the current re
Since 2017 and Symfony 3.3+ this is now very simple.
# app/config/services.yml
services:
_defaults:
autowire: true
App\:
resource: ../../src/App
RequestStack
in service via Constructor InjectionrequestStack = $requestStack;
}
public function someMethod()
{
$request = $this->requestStack->getCurrentRequest();
// ...
}
}
Request
as action method argument...;
}
}
Nothing more is needed.
Happy coding!