我们正在制作具有管理面板的应用程序,并且在其下面有多名员工。 员工只能查看数据并进行编辑和更新。 我已经研究过ACL组件,但我不能理解它,我们可以得到另一个 链接它。
So I have store role admin , employee.
On user controller when users login it checks whether it is admin or employee
But it is not working can you suggest whats the problem in code.
public function beforeFilter()
{
parent::beforeFilter();
$userDetail=$this->Auth->request->data['User'];
$role = $this->User->findByEmail($userDetail['username']);
if($role['User']['role'] == "admin") {
$this->Auth->allow('*');
}else {
$this->Auth->allow('add','edit');
}
答案 0 :(得分:2)
试试这个 -
public function beforeFilter()
{
parent::beforeFilter();
$role = $this->Auth->user('role');
if($role == "admin") {
$this->Auth->allow('*');
}else {
$this->Auth->allow('add','edit');
}
}