jneto
(Joel Neto)
1
Hello, i can’t make it work.
If the expression is true, the access is denied, but if is false, the access is granted .
Is this the normal behavior ?
public function accessRules() {
return array(
array('allow ',
'actions' => array( 'admin', 'index' ),
'users'=>array('@'),
// 'expression' => ' 1===1 '
'expression' => ' Yii::app()->controller->checkAccess()'
),
array('deny', // deny all other actions
'users' => array('?'),
),
);
}
public function checkAccess() {
return 1===1;
$item_name = Yii::app()->controller->id.".".Yii::app()->controller->action->id;
//return Yii::app()->user->checkAccess($item_name);
}
kjra1707
(Kjra 17071989)
2
you can use this:
.............
public function goToLogin() {
// redirect to link login
}
public function checkAccess() {
return Yii::app()->user->isAdmin;
}
public function accessRules() {
return array(
array(
'allow', // Allow all exec action login
'actions' => array('login'),
'users' => array('*'),
),
array('allow', // Alow If the expression is true
'users' => array('@'),
'expression' => array($this, 'checkAccess'),
),
array('deny', // deny all users
'users' => array('*'),
'deniedCallback' => array($this, 'goToLogin'),
),
);
}
...............
jneto
(Joel Neto)
3
thanks. Found the problem.
array('allow ', have a empty space in allow