简体   繁体   中英

Zend Framework 1 ini config for ACL

So I have Zend_ACL set-up(based on this: Zend Framework: need typical example of ACL ).

And I have a config file for setting permissions, but my problem is how do I give access to multiple roles to a specific 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

So the problem is this one:

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

So my question is how do I set this up in order for multiple roles to have access.

I believe you can tweak the code to make it work for you. Change the ini like

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

Then change the code from 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);
                    }
                }
            }

        }
    }
}

I haven't tested this code, but my understanding is that it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM