Identifier "request_context" is not defined with silex

Flattr this
Tweet this: Identifier
Dent this: Identifier
Tags: PHP, Silex, Symfony2, Twig
Datum: 08.11.2011 19:48:59

If you ever receive a message like:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "request_context" is not defined.' in phar:///.../vendor/silex/silex.phar/vendor/pimple/lib/Pimple.php on line 12
And it is not directly about the AsseticExtension in Silex-Extensions,it is probably because some of your code wants access to the url_generator - in my case it was my own Routing-Extension for twig.

First some background informations why it happens.

The problem is that some Extensions - like the url_generator - need access to the requestContext, which is defined after you have already called $app->run(); so in your bootstrap-code that probably has not happened.

The creation of the RequestContext is inside Silex\Application::onKernelRequest (Line may differ - works current master).

There are too solutions to the problem - either you lazyload the url_generator by passing in the app instead of the url_generator and access it only when you really need it or you let Silex run your code inside Silex\Application::onKernelRequest by putting it in a closure as a callback to add it to the dispatcher as a listener for the SilexEvents::BEFORE-Event - which is triggered inside Silex\Application::onKernelRequest.


Trackbacks (0)

Trackbackurl: http://www.robo47.net/trackback/blogentry/211

Es sind keine Trackbacks vorhanden.


Kommentare (0)

Es sind noch keine Kommentare vorhanden.

Die Kommentare zu diesem Beitrag sind gesperrt.

You liked it ? Link it on your homepage or blog: