Cakephp 3 在控制器中获得授权
Cakephp 3 isAuthorized in controller
在控制器中,我试图提供访问方法 'report',其中 user_type=3。我试过下面的代码。但是用户3在report方法中仍然无法访问
我试过的代码:
public function isAuthorized( $user )
{
if ( $user['user_type'] == 2 ) {
return true;
}elseif($user['user_type'] == 3){
$this->Auth->allow(['report']);
}else
return false;
}
如何为 user_type=3
提供访问报告方法
调用 isAuthorized
时,已经检查了 allow
列表。你可以使用
if ($user['user_type'] == 3 && $this->action == 'report')
或者其他更早的地方(比如 beforeFilter
),以某种方式(细节将非常特定于应用程序)获取用户并做你的
if ($user['user_type'] == 3) {
$this->Auth->allow(['report']);
}
在控制器中,我试图提供访问方法 'report',其中 user_type=3。我试过下面的代码。但是用户3在report方法中仍然无法访问
我试过的代码:
public function isAuthorized( $user )
{
if ( $user['user_type'] == 2 ) {
return true;
}elseif($user['user_type'] == 3){
$this->Auth->allow(['report']);
}else
return false;
}
如何为 user_type=3
调用 isAuthorized
时,已经检查了 allow
列表。你可以使用
if ($user['user_type'] == 3 && $this->action == 'report')
或者其他更早的地方(比如 beforeFilter
),以某种方式(细节将非常特定于应用程序)获取用户并做你的
if ($user['user_type'] == 3) {
$this->Auth->allow(['report']);
}