Yii Framework Forum: how to using access roles expression - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to using access roles expression Rate Topic: *---- 1 Votes

#1 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 04:36 AM

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?
belajar itu mudah..
0

#2 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 131
  • Joined: 23-January 12
  • Location:Paris - France

Posted 18 April 2012 - 04:55 AM

I'm using:

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


but that mean that the isAdmin function must be declared
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 18 April 2012 - 05:03 AM

Hi, expressions are eval'd, so
'expression'=>'Yii::app->user->getState("level")== "admin"',

0

#4 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 05:19 AM

View Postbennouna, on 18 April 2012 - 05:03 AM, said:

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"',
			),

belajar itu mudah..
0

#5 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 05:21 AM

View Postragua, on 18 April 2012 - 04:55 AM, said:

I'm using:

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


but that mean that the isAdmin function must be declared

where i must declare isAdmin function?
belajar itu mudah..
0

#6 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 18 April 2012 - 05:26 AM

View Postteguh11, on 18 April 2012 - 05:19 AM, said:

i got error message when i clicked update.
You are not authorized to perform this action.


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

  • Have you tried $user->param instead of Yii::app()->user->getState(param), like this
    'expression'=>'$user->user_biasa == "user"',

  • Where do you set "user_biasa" in your app?

0

#7 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 05:33 AM

View Postbennouna, on 18 April 2012 - 05:26 AM, said:

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

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');

belajar itu mudah..
0

#8 User is offline   VINAY Kr. SHARMA 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 146
  • Joined: 13-September 11
  • Location:Gurgaon

Posted 18 April 2012 - 05:43 AM

View Postteguh11, on 18 April 2012 - 04:36 AM, said:

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')
        ),

VINAY Kr. SHARMA
@vinaykrsharma
Facebook ID: vinaykrsharma
Blog

Co-operation comes from friendship, friendship comes from trust, and trust comes from kind-heartedness.
0

#9 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 05:45 AM

View Postbennouna, on 18 April 2012 - 05:26 AM, said:


  • Have you tried $user->param instead of Yii::app()->user->getState(param), like this
    'expression'=>'$user->user_biasa == "user"',

  • Where do you set "user_biasa" in your app?



this work....
thank you very much...
belajar itu mudah..
0

#10 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 23 April 2012 - 10:58 PM

View Postteguh11, on 18 April 2012 - 05:45 AM, said:

this work....
thank you very much...


where did you set "user_biasa"?
0

#11 User is offline   xent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 14-November 10

Posted 24 April 2012 - 02:22 AM

@kfahmi
you can write in UserIdentity
xent

My first app: School Information System
Find error? Post here
My Blog
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users