teguh11
(Teguhkrstianto)
April 18, 2012, 9:36am
1
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?
ragua
(Brice)
April 18, 2012, 9:55am
2
I’m using:
'expression'=>'$user->isAdmin()'
but that mean that the isAdmin function must be declared
abennouna
(Abennouna)
April 18, 2012, 10:03am
3
Hi, expressions are eval’d, so
'expression'=>'Yii::app->user->getState("level")== "admin"',
teguh11
(Teguhkrstianto)
April 18, 2012, 10:19am
4
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"',
),
teguh11
(Teguhkrstianto)
April 18, 2012, 10:21am
5
where i must declare isAdmin function?
abennouna
(Abennouna)
April 18, 2012, 10:26am
6
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]
teguh11
(Teguhkrstianto)
April 18, 2012, 10:33am
7
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');
teguh11:
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?
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')
),
teguh11:
this work…
thank you very much…
where did you set "user_biasa"?
xent
(Bro Xentauri)
April 24, 2012, 7:22am
11
@kfahmi
you can write in UserIdentity