On occasion, you may need direct access to the layout object. There are three ways you can do this:
-
Within view scripts: use the
layout()view helper, which returns theZend_Layoutinstance registered with the front controller plugin.
<?php $layout = $this->layout(); ?>
Since it returns the layout instance, you can also simply call methods on it, rather than assigning it to a variable.
-
Within action controllers: use the
layout()action helper, which acts just like the view helper.// Calling helper as a method of the helper broker: $layout = $this->_helper->layout(); // Or, more verbosely: $helper = $this->_helper->getHelper('Layout'); $layout = $helper->getLayoutInstance();As with the view helper, since the action helper returns the layout instance, you can also simply call methods on it, rather than assigning it to a variable.
-
Elsewhere: use the static method
getMvcInstance(). This will return the layout instance registered by the bootstrap resource.$layout = Zend_Layout::getMvcInstance();
-
Via the bootstrap: retrieve the layout resource, which will be the
Zend_Layoutinstance.$layout = $bootstrap->getResource('Layout');Anywhere you have access to the bootstrap object, this method is preferred over using the static
getMvcInstance()method.




