ZF uses an action helper called the ViewRenderer by default. This action helper instantiates and stores a Zend_View object, which is subsequently injected into other objects. The view object is stored in the ViewRenderer's view property. You can get the ViewRenderer instance, and thereby the view instance, with the Action Helper broker:

$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer';
$view = $viewRenderer->view;

However, if you're accessing the view early in the dispatch process – before an action is actually dispatched, for example – then you may need to initialize the view first:

if (!isset($viewRenderer->view)) {
$view = $viewRenderer->view;

If you are using and have already initialized Zend_Layout, you can access the view object much more succinctly:

$view = Zend_Layout::getMvcInstance()->getView();

This proxies to the ViewRenderer and performs all of the steps above for you.

Posted in: Zend

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677