使用 cake acl 我正在尝试为登录用户设置权限。我在登录功能中有这个:
if ($user = $this->Auth->user()) {
CakeLog::write('debug', 'this->Auth->user');
//debug($user['User']);
$userGroup = $this->User->Group->findById($user['User']['group_id']);
$aro = $this->Acl->Aro->find('first', array(
'conditions' => array(
'Aro.model' => 'Group',
'Aro.foreign_key' => $this->_user['User']['group_id'],
),
));
$acos = $this->Acl->Aco->children();
foreach ($acos as $aco) {
$permission = $this->Acl->Aro->Permission->find('first', array(
'conditions' => array(
'Permission.aro_id' => $aro['Aro']['id'],
'Permission.aco_id' => $aco['Aco']['id'],
),
));
if (isset($permission['Permission']['id'])) {
if ($permission['Permission']['_create'] == 1 ||
$permission['Permission']['_read'] == 1 ||
$permission['Permission']['_update'] == 1 ||
$permission['Permission']['_delete'] == 1) {
$this->Session->write(
'Auth.Permissions.' . $permission['Aco']['alias'], true
);
if (!empty($permission['Aco']['parent_id'])) {
$parentAco = $this->Acl->Aco->find('first', array(
'conditions' => array(
'id' => $permission['Aco']['parent_id']
)
));
$this->Session->write(
'Auth.Permissions.' . $permission['Aco']['alias']
. '.' . $parentAco['Aco']['alias'], true
);
}
}
}
}
}
我收到此错误:
未定义属性:UsersController::$_user [APP\controllers\users_controller.php,第 82 行]
我可以将 '$this->_user['User']['group_id']' 更改为 '$this->_user['User']['group_id']',这样是否正确。如果不是,我应该设置什么 public $_user = ?
谢谢