简体   繁体   中英

Zend Unset Action helper from controller action

Zend framework talk.I'm initializing in my bootstrap class My_Action_Helper_Custom (extending Zend_Controller_Action_Helper_Abstract) to make it available to all of my controllers.

Could I just disable it for a specific action where I dont need it?

thanks

Luca

Are you referring to disabling the preDispatch() or postDispatch() hooks for a particular controller action?

If so, I'd add some form of blacklist property to the helper, for example

/**
 * @var array
 */
private $blacklistActions = array();

public function addBlacklistAction($action)
{
    // store actions in string form
    // eg, module.controller.action
    $this->blacklistActions[] = $action;
}

public function preDispatch()
{
    $request = $this->getRequest();
    $action = sprintf('%s.%s.%s',
            $request->getModuleName(),
            $request->getControllerName(),
            $request->getActionName());
    if (in_array($action, $this->blacklistActions)) {
        return;
    }

    // the rest
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM