コマンドラインが使えない環境でacoテーブルを更新するには、以下のような関数を追加して実行する。
例えば、studentモデルを追加する。
まず、user/reitnitDBにアクセスすることでDBが更新されるよう、usersContorllerに下を追加する。
最初にStudentsのみ追加。
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('reinitDB');
}
public function reinitDB() {
$this->Acl->Aco->create(array('parent_id' => 1, 'alias' => 'Students', 'model' => ''));
$this->Acl->Aco->save();
echo "all done";
exit;
}
user/reitnitDBにアクセスする。
acoテーブルに一行追加されているはず。
今回追加した分のIDを93とする。
下層のページのために、下記を追加。
$aliasesの配列に含まれるページをacoテーブルに追加していくもの。
public function reinitDB() {
$aliases = array(
'admin_index',
'admin_add',
'admin_edit',
'admin_delete',
'admin_view',
'admin_course_edit',
'admin_couse_take',
'index',
'add',
'edit',
'view',
);
foreach ($aliases as $key => $value) {
$this->Acl->Aco->create(array('parent_id' => 93, 'alias' => $value, 'model' => ''));
$this->Acl->Aco->save();
}
echo "all done";
exit;
}
そして再度user/reitnitDBにアクセス。
またテーブルの更新を確認出来るはず。
次にreinitDB() で、アクセス権限の編集を行う。
group_id = 1 or 2のときにStudentsすべて、
group_id = 3 のときはStudents/view, editへのアクセスを許可するので、こんな感じになる。
public function reinitDB() {
$group = $this->User->Group;
//Allow admins to everything
$group->id = 1;
$this->Acl->allow($group, 'controllers');
//allow managers to posts and widgets
$group->id = 2;
$this->Acl->allow($group, 'controllers/Students');
//allow users to only add and edit on posts and widgets
$group->id = 3;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Students/view');
$this->Acl->allow($group, 'controllers/Students/edit');
//we add an exit to avoid an ugly "missing views" error message
echo "all done";
exit;
}