I have a function in my WebUser getIsAdmin
public function getIsAdmin() {
$user = $this->loadUser(Yii::app()->user->id);
if ($user === null) {
return false;
}
return intval($user->user_level_id) == AccountModule::USER_LEVEL_ADMIN;
}
Yet my rule in my controller isn’t working
array('allow',
'actions'=>array('index','create','upload'),
'users'=>array('admin'),
),
Where do I set so the user is an admin?
The
usersproperty in an access control filter just check for the user name only, ie it checks forYii::app()->user->name=='admin'. In your scenario you can use theexpressionproperty. The access is granted only if the expression evaluated to true. The$uservariable can be used in an expression as an alias forYii::app()->user. So your condition would be