Cannot call setNoRender () in viewRenderer in postDispatch () in Zend Framework controller plugin

Calling setNoRender () or even any viewRenderer helper methods does not seem to affect the controller plugin.

class TestPlugin extends Zend_Controller_Plugin_Abstract { public function postDispatch(Zend_Controller_Request_Abstract $request) { $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setNoRender(); } } 

The view script still displays. And the plugin definitely works, as I can put the echoes here and they will be output.

+4
source share
4 answers

You will need to put this in your postDispatch your controller plugin.

 $viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer'); $viewRenderer->setNeverRender(true); 
+4
source

Does this work in any other intercepts like preDispatch ()?

+1
source

if someone wants to disable both the layout and viewing using the controller plugin, here is the preDispatch hook that I worked with through various articles and answers, including this one. Hope this helps someone and saves time.

 // in Controller Plugin public function preDispatch(){ //if its an AJAX request then disable layout and view. if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax'])){ // disable layout $layout = Zend_Controller_Action_HelperBroker::getExistingHelper('Layout'); $layout->disableLayout(); // disable view $viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer'); $viewRenderer->setNeverRender(true); } } 
+1
source

I also could not figure out how to do this from the initialization of the script controller plugin. However, there is an easy way around this problem. You can do this in the preDispatch of your base controller with the following standard code:

 $this->_helper->viewRenderer->setNoRender(true); 

All your controllers must inherit from this base controller, which itself extends Zend_Controller_Action.

0
source

Source: https://habr.com/ru/post/1345079/


All Articles