2017-06-02 97 views
0

所以我有Zend_ACL設置(基於此:Zend Framework: need typical example of ACL)。Zend Framework 1 ACL的ini配置

而且我有權限設置一個配置文件,但我的問題是我怎麼給一個特定的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 

所以我的問題是我如何設置這個以便多個角色有權訪問。

回答

0

我相信你可以調整代碼,使它爲你工作。更改像

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

的INI然後將代碼從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); 
        } 
       } 
      } 

     } 
    } 
} 

改變我還沒有測試此代碼,但我的理解是,它應該工作。

+0

它的工作原理,你忘了添加$到$ this-> deny(multipleRoles,$ controller,$ action); – Uffo

+0

我修復了它,並對其進行了測試,它很有用,謝謝! – Uffo

+0

好的。很高興知道它爲你工作! – ksoni