Get a URL parameter BEFORE $app->run()?


#1

Is it possible to get a URL parameter (i.e. $container->request->getAttribute('foo')) BEFORE $app->run() is called?

I’m trying to add a function to Twig that needs a URL parameter. I load the function immediately after registering the Twig service and when I call $container->request->getAttribute('foo') in the function I get back null.


#2

I think that the rendering of your twig is done after the request has fired.
So lets assume you have an url param foo,
then in the controller where you render the normal twig template you add foo and its value to the data that twig uses to render.

Inside your twig template there is a call to your extension.

{{ myExtensiom(foo) }}

twig will first render the template, then sees your extension and calls it, with the value that foo represents.

In my basecontroller, I have my view ( $this->view = $container->view;)
and in that I can put a global value, available to all templaes that I render.
$this->view->offsetSet(‘foo’, ‘a value that you decide’);
In this case, you don’t have to set it at each controller action :wink:

Hope this helps.