【问题标题】:Zend Unset Action helper from controller actionZend Unset Action helper 来自控制器动作
【发布时间】:2011-05-24 22:57:59
【问题描述】:

Zend 框架谈话。我正在我的引导类 My_Action_Helper_Custom 中进行初始化(扩展 Zend_Controller_Action_Helper_Abstract),以使其可用于我的所有控制器。

我可以在不需要的特定操作中禁用它吗?

谢谢

卢卡

【问题讨论】:

    标签: php zend-framework controller helpers


    【解决方案1】:

    您是指禁用特定控制器操作的 preDispatch()postDispatch() 挂钩吗?

    如果是这样,我会向助手添加某种形式的黑名单属性,例如

    /**
     * @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
    }
    

    【讨论】:

    • 我应该从控制器调用 addblacklistAction 吗??
    • @luca 我会在将它添加到帮助代理之前从 Bootstrap 执行此操作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2013-08-11
    • 2011-03-01
    相关资源
    最近更新 更多