有问题结合Zend_Acl里和Zend_Navigation

我有一个扩展Zend_Controller_Plugin_Abstract,看起来像这样一个Federico_Plugin_Acl:

class Federico_Plugin_Acl extends Zend_Controller_Plugin_Abstract { private $_acl = null; private $_auth = null; const DEFAULT_ROLE = 'guest'; public function __construct($auth) { $this->_auth = $auth; $this->_acl = new Zend_Acl(); $this->_acl->addRole(new Zend_Acl_Role(self::DEFAULT_ROLE)); $this->_acl->addRole(new Zend_Acl_Role('user'), self::DEFAULT_ROLE); $this->_acl->addRole(new Zend_Acl_Role('admin'), 'user'); $this->_acl->addResource(new Zend_Acl_Resource('index')); $this->_acl->addResource(new Zend_Acl_Resource('users')); $this->_acl->addResource(new Zend_Acl_Resource('about')); $this->_acl->addResource(new Zend_Acl_Resource('gisele')); $this->_acl->addResource(new Zend_Acl_Resource('admin')); $this->_acl->allow('guest', 'index'); $this->_acl->allow('guest', 'about'); $this->_acl->deny('guest', 'gisele'); $this->_acl->deny('guest', 'users'); $this->_acl->allow('user', 'users', array('index')); $this->_acl->allow('admin', 'users'); $this->_acl->allow('admin', 'gisele'); } public function preDispatch(Zend_Controller_Request_Abstract $request) { if ($this->_auth->hasIdentity()) { $role = $this->_auth->getStorage()->read()->role; } else { $role = self::DEFAULT_ROLE; } $action = $request->getActionName(); $controller = $request->getControllerName(); if ($this->_acl->has($controller)) { if (!$this->_acl->isAllowed($role, $controller, $action)) { $request->setActionName('login'); $request->setControllerName('index'); } } } }

这种方法是在我的引导,使这个类的使用:

protected function _initNavigation() { $this->_auth = Zend_Auth::getInstance(); $this->_acl = new Federico_Plugin_Acl($this->_auth); $this->bootstrap('view'); $view = $this->getResource('view'); $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav'); $navigation = new Zend_Navigation($config); $roleAuth = $this->_auth->getIdentity(); if(null == $roleAuth) $role = 'guest'; else $role = $roleAuth->role; $view->navigation($navigation)->setAcl($this->_acl)->setRole($role); }

通过这些配置设置这样,我得到以下错误:

捕获的致命错误:传递给Zend_View_Helper_Navigation_HelperAbstract :: SETACL(参数1)必须是Zend_Acl里的一个实例,Federico_Plugin_Acl实例给出,堪称/home/fiodorovich/public_html/gisele/application/Bootstrap.php上线118和在/ home定义/fiodorovich/library/ZendFramework/library/Zend/View/Helper/Navigation/HelperAbstract.php线333调用堆栈

这是可以预料的,因为Federico_Plugin_Acl是Zend_Controller_Plugin_Abstract的全部实例......不过,如果我延长Zend_Acl里,而不是我得到这个错误:

Fatal error: Zend_Acl_Role_Registry_Exception: Role 'guest' not found in /home/fiodorovich/library/ZendFramework/library/Zend/View/Helper/Navigation/HelperAbstract.php on line 522

所以......我一直想了一会儿让这件事解决了,......但似乎没有得到这个正常工作......对我缺少的是什么在这里的任何想法?

--------------解决方案-------------

Zend_Controller_Plugin_Abstract和Zend_Acl里有completelly不同的东西。 你想要做的就是让ACL对象出你的插件(现在是私人部分),并把它传递到

$view->navigation($navigation)->setAcl(<here>);

分类:Zend框架 时间:2015-03-15 人气:0
本文关键词: Zend框架,Zend的ACL
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.537 (s). 10 q(s)