Yii Framework Forum: How Do I Set The Access Roles ? - Yii Framework Forum

Jump to content

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

How Do I Set The Access Roles ? Rate Topic: -----

#1 User is offline   Tenbe 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-December 13

Posted 15 April 2014 - 08:20 AM

Hi everyone

I have the following code in a controller.
How and where do I set the role to 'admin' or something else let say 'user'? I want to be able to set these value in the code uppon login.
Thanks

public function accessRules()
{
   return array(
       array('allow'
             'actions'=>array('index','view'),
             'users'=>array('admin'),
             'roles'=>array('admin'),
      ),
  );
} 

0

#2 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 10:03 AM

Hi,

Take a look this and this is a good module that can help you link
0

#3 User is offline   Gogo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 17-May 12
  • Location:Sofia

Posted 15 April 2014 - 10:05 AM

Maybe this topic will help you, too.
0

#4 User is offline   Tenbe 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-December 13

Posted 15 April 2014 - 10:40 AM

Thanks for this,

But I don't want to use a table for this as it's just a simple check based on the URL and the infos that the user gave at loggin.
if internal he should be admin, if external then simple user without access to that controller.
0

#5 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 16 April 2014 - 07:33 PM

View PostTenbe, on 15 April 2014 - 10:40 AM, said:

Thanks for this,

But I don't want to use a table for this as it's just a simple check based on the URL and the infos that the user gave at loggin.
if internal he should be admin, if external then simple user without access to that controller.

I believe you would need to extend the WebUser, and override the checkAccess function to use 'roles'
public function checkAccess($username) {
   //Do your check
   return true; //if they can do it
   return false; //if they can't
}


Another option would be to add an isAdmin() function:
public function getIsAdmin() {
   //Do your check
   return true; //if they can do it
   return false; //if they can't
}


   return array(
       array('allow'
             'actions'=>array('index','view'),
             'users'=>array('admin'),
             'expression'=>'Yii::app()->user->isAdmin', //<- changed
      ),
  );
   

Do, or do not. There is no 'try.' Jedi Master Yoda
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