When working with the Zend Framework you often need access to the Bootstrap to fetch resources. The classic way to get the bootstrap in most of the examples for the Zend Framework is like this…
$bootstrap = $this->getBootstrap();
However, this method is not globally available, so from an action controller for example, that method would fail. There is an alternative way to get access to the Bootstrap.
$bootstrap = $this->getInvokeArg('bootstrap');
This works because Zend_Application_Bootstrap_Bootstrap registers itself as the front controller parameter bootstrap, which lets us access it from the router, dispatcher, plugins and action controllers.
So, if I had a twig resource I wanted to access from an action controller, I could use the following code…
$bootstrap = $this->getInvokeArg('bootstrap');
$twig = $bootstrap->getResource('twig');
or by chaining accessors, I could reduce this to one line…
$twig = $this->getInvokeArg('bootstrap')->getResource('twig');
For more information, read Zend Framework’s Theory of Operation.