how to using access roles expression

i got a problem with access rules expression.

i try like this.


array('allow', // allow admin user to perform 'admin' and 'delete' actions

        'actions'=>array('admin','delete','create','update'),

        'expression'=>Yii::app->user->getState('level')== 'admin',

        ),



but not working…

how to use expression for access rule?

I’m using:




'expression'=>'$user->isAdmin()'



but that mean that the isAdmin function must be declared

Hi, expressions are eval’d, so


'expression'=>'Yii::app->user->getState("level")== "admin"',

i got error message when i clicked update.


You are not authorized to perform this action.

this is my code.




array('allow', 

       'actions'=>array('update','create'),

	'users'=>array('@'),

	'expression'=>'Yii::app->user->getState("user_biasa") == "user"',

			),

where i must declare isAdmin function?

That means the expression is eval’d to false. (Error code 403).

[list=1]

[*]Have you tried [font="Courier New"]$user->param[/font] instead of [font="Courier New"]Yii::app()->user->getState(param)[/font], like this


'expression'=>'$user->user_biasa == "user"',

[*]Where do you set "user_biasa" in your app?

[/list]

yes. and now what should i do for this access rules?

i need only "user_biasa" for access this action…

i set in useridentity like this


$this->setState('user_biasa','user');

Why not you try this:


array('allow', // allow admin user to perform 'admin' and 'delete' actions

        'actions'=>array('admin','delete','create','update'),

        'roles'=> array('admin')

        ),



this work…

thank you very much…

where did you set "user_biasa"?

@kfahmi

you can write in UserIdentity