0
我有工作ACL組
-client
ACL組,分組
-member
-manager
,需要把它們記錄下來,以ALL組各分組
到permissiions添加到所有,所以其他3將繼承它,
什麼是正確的做法呢?
我有工作ACL組
-client
ACL組,分組
-member
-manager
,需要把它們記錄下來,以ALL組各分組
到permissiions添加到所有,所以其他3將繼承它,
什麼是正確的做法呢?
我假定你有必要的用戶組&組模型,你會使用CakePHP的ACL行爲。我還假設你有'acos','aros',&'aros_acos'表。
你需要讓你的組樹類型:
class Groups extends AppModel {
var $actsAs = array('Tree', 'Acl' => array('type' => 'requester'));
function parentNode() {
return null;
}
}
,並在MySQL中,你的組表應該包含以下幾個領域 - ID,PARENT_ID,LFT,rght,姓名(或說明)。前四個字段是必需的,以便樹行爲起作用。
在groups_controller.php:
function add($parentId = null){
if(!empty($this->data)){
if($this->Group->save($this->data)) {
$this->Session->setFlash(__('The group has been saved.', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The group could not be saved. Please try again.', true));
}
}
$this->set(compact('parentId'));
}
在用戶模式:
class User extends AppModel {
var $name = 'User';
var $belongsTo = array('Group');
var $actsAs = array('Acl' => array('type' => 'requester'));
function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
}
if (isset($this->data['User']['group_id'])) {
$groupId = $this->data['User']['group_id'];
} else {
$groupId = $this->field('group_id');
}
if (!$groupId) {
return null;
} else {
return array('Group' => array('id' => $groupId));
}
}
}
現在每次你添加一個新的組或用戶,該AROS表將自動更新。 然後您需要爲AROS_ACOS表上的每個節點設置權限。不幸的是,在CakePHP中沒有簡單的方法來做到這一點。
你可以把這個代碼裏groups_controller.php,然後運行/組/ build_acl每次你添加/刪除用戶/組:
function initDB() {
$group =& $this->User->Group;
//Allow ALL to everything
$group->id = 1;
$this->Acl->allow($group, 'controllers');
//allow managers to posts and widgets
$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');
$this->Acl->allow($group, 'controllers/Widgets');
//allow client to only add and edit on posts and widgets
$group->id = 3;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts/add');
$this->Acl->allow($group, 'controllers/Posts/edit');
$this->Acl->allow($group, 'controllers/Widgets/add');
$this->Acl->allow($group, 'controllers/Widgets/edit');
//we add an exit to avoid an ugly "missing views" error message
echo "all done";
exit;
}
我希望這有助於。大部分代碼都來自CakePHP在線文檔。