gpt4 book ai didi

zend-framework - 在 View 中使用 Zend_Acl 来显示/隐藏部分 View 的方法是什么

转载 作者:行者123 更新时间:2023-12-04 06:50:23 25 4
gpt4 key购买 nike

我想知道使用 Zend_Acl 显示/隐藏部分 View 的方法是什么?我想我会

  • 创建一个Controller Plugin,通过登录用户+acl查看
     $this->view->loggedInUser = Zend_Auth::getIdentity();
    $this->view->acl = Zend_Registry::get('acl');
  • 然后在 View 脚本中执行类似的操作
    $this->acl->isAllowed($this->view->loggedInUser, 'resource', 'privilege');

  • 或者,还有更好的方法?还是应该使用 View 助手?返回一个 bool 值是否允许登录用户?

    最佳答案

    你在 View 中使用它,所以对我来说 ViewHelper 是正确的地方 - 我已经这样做过一次:

    class Zend_View_Helper_HasAccess extends Zend_View_Helper_Abstract
    {
    private $_acl;
    public function hasAccess($role, $controller, $action)
    {
    if (!$this->_acl) {
    $this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
    //In yout case registry, but front controller plugin is better way to implement ACL
    }
    return $this->_acl->isAllowed($role, $controller, $action);
    }
    }

    关于zend-framework - 在 View 中使用 Zend_Acl 来显示/隐藏部分 View 的方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4578391/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com