Zend_Acl 查找所有继承的角色
我得到了角色链:
acl.roles.guest = null
acl.roles.member = "guest"
acl.roles.admin = "member"
acl.roles.owner = "admin"
在 .....Controller/Action/Helper/Acl.php 中我存储了 _acl 对象
这是获取我的角色和父母列表的方法吗?
$this->_acl->getParents ( 'admin' )
应该
admin, member, guest
作为数组或字符串返回(例如逗号分隔)
I got chain of roles:
acl.roles.guest = null
acl.roles.member = "guest"
acl.roles.admin = "member"
acl.roles.owner = "admin"
in .....Controller/Action/Helper/Acl.php I have stored _acl object
Is it a way to get list of my role and parents ?
$this->_acl->getParents ( 'admin' )
should return
admin, member, guest
as array, or string (eg comma delimited)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
getRoles()
- 返回已注册角色的数组。检查每个角色
inheritsRole()
- 返回来 true 当且仅当 $role 继承自 $inherit请参阅 API 文档
Zend_Acl
,位于 http://framework.zend.com/apidoc/core/Zend_Acl/Zend_Acl.html示例,
该示例将返回类似
替代方案的
内容实际上是
Zend_Acl_Role_Registry
中的getParents()
方法,但似乎没有办法通过Zend_Acl
的公共接口访问该方法。请参阅源代码扩展
Zend_Acl
以获得方法getParentsForRole() 是很简单的
不过:这只会返回直接父级,例如,对于“owner”,它返回“admin”,因此您可能需要添加另一种方法来递归地获取所有父级到最后一个:
示例
将导致
这与对
getParents
的单个调用将返回的结果一致。如果您不需要,您也可以使用第一个示例中的 foreach 代码,例如You can use
getRoles()
- Returns an array of registered roles.and then check each of these with
inheritsRole()
- Returns true if and only if $role inherits from $inheritSee the API docs
Zend_Acl
at http://framework.zend.com/apidoc/core/Zend_Acl/Zend_Acl.htmlExample
which would then return something like
Alternative
There actually is a
getParents()
method inZend_Acl_Role_Registry
, but there doesn't seem to be a way to access that through the public interface ofZend_Acl
. See the sourcecodeIt is trivial to extend
Zend_Acl
to have a methodgetParentsForRole()
though:This does only return the immediate parents though, e.g. for 'owner' it returns 'admin', so you might want to add another method to fetch all the parents recursively down to the last one:
Example
would result in
which is in accordance with what a single call to
getParents
would return. If you dont need that, you can also just use the foreach code from the first example, e.g.