Search code examples
zend-frameworkcontrolleractionhelperviewhelper

How to disable view renderer from a controller action helper ?


In a controller, I can call viewRenderer helper like this :

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

How can I call viewRenderer in a controller action helper? Assume that I have a Controller action helper :

class Zend_Controller_Action_Helper_Ajaxrequest extends Zend_Controller_Action_Helper_Abstract{

   public function test(){
       //what I should do here
   }
}

Solution

  • viewRenderer in your example is actually an action helper, not a view helper.

    To call action helpers, use the helper broker:

    $helper = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
    $helper->setNoRender(true);
    

    If you actually want to call view helpers, you need a view instance. You can get one from the controller:

    $controller = $this->getActionController();
    
    //call the url view helper
    $controller->view->url(...);