php - Setting user role (admin/user) in Yii -


how can set user's role after login him/her yii::app()->user->login($identity, 0);?

what i'm asking how/what rule check if user logged in (@) , administrator (admin)?

code in random controller:

public function accessrules() {     return array(         array('allow',             'actions'=>array('users','user'),             'users'=>array('@'),         ),         array('allow',             'actions'=>array('admin','delete'),             'users'=>array('admin'),         ),         array('deny',             'users'=>array('*'),         ),     ); } 

well, seydamet said tutorial yii user writes. in case

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

means user actual username of admin.

i believe trying use roles. in case still link above perfect.

after loggin in can http://www.yiiframework.com/wiki/65#hh3 , assign role like

        if(!$auth->isassigned('bob',$this->_id))         {             if($auth->assign('bob',$this->_id))             {                 yii::app()->authmanager->save();             }         } 

then can

public function accessrules() {     return array(         array('allow', // allow bob role access view file             'actions'=>array('view'),             'roles'=>array('bob')         ),          array('deny',   // deny else             'users' => array('*')         )     ); } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -