InterviewSolution
| 1. |
How Can I Retrieve The View Object Within A Plugin Or Arbitrary Code? |
|
Answer» 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: $vsewRenderer Zend,, Conrroller,,A ction_HelperBroke::getStaticHelper(viewRenderer); $view =$viewRenderer-->viewHowever, 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)) { $viewRendere-->intViewO(); } $vi ew = Svi ewRenderer-- >view;If you are USING and have already initialized Zend_Layout, you can ACCESS the view object much more succinctly: $view = Zend_Layo ut::getMvcInstance()-- >getView();This proxies to the ViewRenderer and performs all of the steps above for you. 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: $vsewRenderer Zend,, Conrroller,,A ction_HelperBroke::getStaticHelper(viewRenderer); 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 you are using and have already initialized Zend_Layout, you can access the view object much more succinctly: This proxies to the ViewRenderer and performs all of the steps above for you. |
|