How Do I Set The Access Roles ?

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

      ),

  );

} 

Hi,

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

Maybe this topic will help you, too.

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

      ),

  );