A. Martyn A. Martyn - 2 months ago 10
PHP Question

Get master request in Symfony 2.4

When rendering another controller from the view, master request gets lost - this means that, for example, GET parameters will not be available in that rendered (included) controller.

What is the way to access the query string in rendered controllers, except accessing $_GET directly (this works).

I've found some legacy code in the project which does the thing, but it's deprecated in 2.4 and will be removed in 3.0 already:

$this->container->get('request_stack')->getMasterRequest();


Here $this->container is the ContainerInterface.

Answer

http://api.symfony.com/master/Symfony/Component/HttpFoundation/RequestStack.html

From the RequestStack you can get the master request $stack->getMasterRequest().

The request as a service is deprecated $this->container->get('request'), but this stack replaced it.