I am working on a Zend Framework based app, and in controller plugins, I can get Zend_View object with the following methods, someone please tell me which approach is better and why?
$view = Zend_Layout::getMvcInstance()->getView();
or
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
if (null === $viewRenderer->view)
$viewRenderer->initView();
$view = $viewRenderer->view;
It is better to pull it from the viewRenderer because then you're sure you'll always get it. You may not be using Layout in some contexts and then you won't get the view through the layout.
So, to be on the save side, pull it from the viewRenderer, it's more direct anyways and therefore faster too.