2014-06-17 66 views
0

我想用CakeDc用戶插件實現一個僅限組的acl。我遵循蛋糕的「簡單的Acl控制器應用指南」。 我有以下的用戶模型:CakeDc:用戶插件僅限組acl

public $belongsTo = array(
    'Role' => array(
     'className' => 'Role', 
     'foreignKey' => 'role_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ) 
); 

public $actsAs = array('Acl' => array('type' => 'requester', 'enabled' => false)); 

public function parentNode() { 
    if (!$this->id && empty($this->data)) { 
     return null; 
    } 
    if (isset($this->data['User']['role_id'])) { 
     $roleId = $this->data['User']['role_id']; 
    } else { 
     $roleId = $this->field('role_id'); 
    } 
    if (!$roleId) { 
     return null; 
    } else { 
     return array('Role' => array('id' => $roleId)); 
    } 
} 

public function bindNode($user) { 
    return array('model' => 'Model.Role', 'foreign_key' => $user['User']['role_id']); 
} 

而且我有這個的榜樣:

public $actsAs = array('Acl' => array('type' => 'requester')); 

public function parentNode() { 
    return null; 
} 
    public $hasMany = array(
    'User' => array(
     'className' => 'User', 
     'foreignKey' => 'role_id', 
     'dependent' => false, 
     'conditions' => '', 
     'fields' => '', 
     'order' => '', 
     'limit' => '', 
     'offset' => '', 
     'exclusive' => '', 
     'finderQuery' => '', 
     'counterQuery' => '' 
    ) 
); 

我似乎並不奏效,但它仍然問我的ARO。

AclNode::node() - Couldn't find Aro node identified by "Array ([Aro0.model] => User [Aro0.foreign_key] => 51) " 

我該如何糾正這個錯誤? 在此先感謝。

回答

0

在user.php的嘗試:

public function bindNode($user) { 
    return array('model' => 'Role', 'foreign_key' => $user['User']['role_id']); 
} 

,而不是

public function bindNode($user) { 
    return array('model' => 'Model.Role', 'foreign_key' => $user['User']['role_id']); 
} 
-1

設置userModelAuthComponent的授權方法。它的名稱不是標準(用戶),因爲您正在擴展Users組件的用戶模型。然而,Auth和Acl必須知道。