Zend Framework 1 ini配置ACL

时间:2017-06-02 17:52:10

标签: php zend-framework acl

所以我设置了Zend_ACL(基于此:Zend Framework: need typical example of ACL)。

我有一个用于设置权限的配置文件,但我的问题是如何将多个角色的访问权限授予特定的controller.action

; roles
acl.roles.guest = null
acl.roles.admin = null
acl.roles.company = null
acl.roles.user = null
acl.roles.super_admin = null

; resources
acl.resources.deny.all.all = guest

acl.resources.allow.index.all = guest
acl.resources.allow.index.all = company

所以问题就出在这个问题上:

acl.resources.allow.index.all = guest
acl.resources.allow.index.all = company

所以我的问题是如何设置它以便多个角色可以访问。

1 个答案:

答案 0 :(得分:0)

我相信您可以调整代码以使其适合您。更改ini就像

一样
acl.resources.allow.index.all = guest,company

然后从Zend Framework: need typical example of ACL

更改代码
protected function _addResources($resources) {          

    foreach ($resources as $permissions => $controllers) {         

        foreach ($controllers as $controller => $actions) {
            if ($controller == 'all') {
                $controller = null;
            } else {
                if (!$this->has($controller)) {
                    $this->add(new Zend_Acl_Resource($controller));
                }
            }

            foreach ($actions as $action => $role) {
                if ($action == 'all') {
                    $action = null;
                }
                if ($permissions == 'allow') {
                    if(strpos($role, ',') !== false) {
                        $multipleRoles = explode(',',$role);
                        $this->allow($multipleRoles, $controller, $action);
                    } else {
                        $this->allow($role, $controller, $action);
                    }
                }
                if ($permissions == 'deny') {
                    if(strpos($role, ',') !== false) {
                        $multipleRoles = explode(',',$role);
                        $this->deny($multipleRoles, $controller, $action);  
                    } else {
                        $this->deny($role, $controller, $action);
                    }
                }
            }

        }
    }
}

我没有测试过这段代码,但我的理解是它应该可以运行。