dps43378 2013-12-18 08:47 采纳率: 0%
浏览 36
已采纳

如何在动作助手中获得$ acl-> isAllowed?

I'm trying to create a action helper for creating a menu. But I don't know how why it doesn't know the function isAllowed. I get the following error message:

Call to a member function isAllowed() on a non-object

<?php
class Zend_Controller_Action_Helper_Menu extends Zend_Controller_Action_Helper_Abstract
{
    private $_acl;
    public function createSubMenu($request,$identity){
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        $identity = $identity->user_role;
        $access = $this->hasAccess($identity,$action,$controller);

        $return;

        $return .= "<ul>";
            $return .= "<li><a href=''>".$identity."</a></li>";
        $return .= "</ul>";

        return $access;
    }

    private function hasAccess($role, $action, $controller)
    {
        $this->_acl = new Zend_Acl();
        if (!$this->_acl) {
            $this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
        }
        return $this->_acl->isAllowed($role, $controller, $action);
    }
}
  • 写回答

1条回答 默认 最新

  • douluyezhen4512 2013-12-18 10:30
    关注

    I'm no Zend expert, but:

    • $this->_acl = new Zend_Acl(); - this will create new ACL object without any roles set, so it is useless (maybe you wanted to do this other way around - first get plugin, and if there isn't one create new?)
    • ->getPlugin('Acl'); - You should use full plugin class name

    I usually create and initiate ACL object in plugin (on preDispatch) and save it in Zend_Registry so i can later use Zend_Registry::get('Zend_Acl')->isAllowed($role, $resource, $privilege);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM