我想在Zend框架中使用ACL来允许资源到角色
我有模块权限和帐户。
特权模块具有用户和特权控制器。 每个控制器都有索引,查看和编辑操作。
如何将行动资源授予角色?我面临的问题是我可以授予对整个模块的访问权限,但我无法访问控制器中的特定操作..
$this->addRole(new Zend_Acl_Role('admin'));
$this->add(new Zend_Acl_Resource('privileges'))
->add(new Zend_Acl_Resource('privileges-privilege'))
->add(new Zend_Acl_Resource('privileges-users'))
->add(new Zend_Acl_Resource('account'))
->add(new Zend_Acl_Resource('default'));
$this->deny('admin'); //deny every thing
$this->allow('admin', 'account');
$this->allow('admin', 'privileges-privilege' , array('index','view','edit'));
我也是另一种方式
$this->add(new Zend_Acl_Resource('privileges'))
->add(new Zend_Acl_Resource('privilege'), 'privileges')
->add(new Zend_Acl_Resource('Privilege'),array('index','view','edit'))
->add(new Zend_Acl_Resource('users', 'privileges'))
->add(new Zend_Acl_Resource('account'))
->add(new Zend_Acl_Resource('account:account'), 'account')
->add(new Zend_Acl_Resource('default'));
$this->deny('admin'); //deny every thing
$this->allow('admin', 'account');
$this->allow('admin', 'Privilege', array('index','view','edit'));
但它不起作用,两种方式都会导致同样的问题,而不会授予对权限模块的任何访问权限!并且只允许帐户模块..
答案 0 :(得分:0)
我做到了,我在模块和控制器之间进行连接,我就这样做了
moduleName-ControllerName。
我传递角色,连接的模块和控制器作为资源和操作是特权。
if (!$this->_acl->isAllowed($role, $request->getModuleName() . '-' . $request->getControllerName(), $request->getActionName())) {
$request->setModuleName('account')
->setControllerName('account')
->setActionName('error');
return false;
}
以及我如何添加资源
$this->add(new Zend_Acl_Resource('privileges'))
->add(new Zend_Acl_Resource('privileges-privilege'))
->add(new Zend_Acl_Resource('privileges-users'))
->add(new Zend_Acl_Resource('privileges-index'))
->add(new Zend_Acl_Resource('account'))
->add(new Zend_Acl_Resource('account-account'))
->add(new Zend_Acl_Resource('default'))
->add(new Zend_Acl_Resource('error'))
->add(new Zend_Acl_Resource('default-index'));
// $this->allow('admin'); //allow every thing
$this->allow('admin', 'account-account');
$this->allow('admin', 'default');
$this->allow('admin', 'default-index');
$this->allow('admin', 'privileges-users', array('index','add-User','get-Group-Users'));
$this->allow('admin', 'privileges-index', 'index');
$this->allow('admin', 'privileges-privilege', array('index', 'get-privileges', 'update-privileges','get-User-Privileges','get-Group-Privileges'));