php - How to assign role and checkaccess method in yii? -


i new in yii role management,
have 2 role admin1,admin2
have 2 controllers , it's action

(1)usercontroller - create,update,delete
(2)categorycontroller - view,create,update

i want give checkaccess method admin1
(1)usercontroller - update,delete
(2)categorycontroller - update

i want give checkaccess method admin2
(1)usercontroller - create,update,delete
(2)categorycontroller - create,view

how can give checkpermission 2 controller particular admin ? appreciated.

here checkaccess method gives me error

class useridentity extends cuseridentity {     private $_id;         public $role;         public $rolename;      /**      * authenticates user.      * @return boolean whether authentication succeeds.      */     public function authenticate()     {         $username = $this->username;         $password = md5($this->password);         $user=login_user::model()->findbyattributes(array('email'=>$username,'password'=>$password,'status'=>'1'));         if(empty($user))         {             $this->errorcode=self::error_username_invalid;         }         elseif($password != $user->password)         {             $this->errorcode=self::error_password_invalid;         }         else         {             $this->_id=$user->userid;             $this->username=$user->email;                         $this->role=$user->roleid;                          $rolequery = "select * role roleid = ".$user->roleid." ";                         $roledata = yii::app()->db->createcommand($rolequery)->queryall();                          if(isset($roledata[0]['title']) && $roledata[0]['title'] != '') {                             $this->rolename = $roledata[0]['title'];                         }                            if($user->roleid != '') {                             $query = "select * rolepermission roleid = ".$user->roleid." , status = 1 ";                             $permissiondata = yii::app()->db->createcommand($query)->queryall();                         }                          $auth=yii::app()->authmanager;                         $rolepemirssion=$auth->createrole($this->rolename);                         foreach($permissiondata $key => $value) {                             $rolepemirssion->addchild($value['controller'].$value['action']);                         }             $this->errorcode=self::error_none;         }         return $this->errorcode==self::error_none;     }  } 

you should use yii access control filters

 class usercontroller extends ccontroller  {    …    public function accessrules()    {        return array(            ...            array('allow',                'actions'=>array('update', 'delete'),                'roles'=>array('admin1'),            ),            array('allow',                'actions'=>array('update'),                'roles'=>array('admin2'),            ),            ...        );    }  }  class categorycontroller extends ccontroller  {    …    public function accessrules()    {        return array(            ...            array('allow',                'actions'=>array('create', 'update', 'delete' ),                'roles'=>array('admin1'),            ),            array('allow',                'actions'=>array('create', 'view'),                'roles'=>array('admin2'),            ),            ...        );    }  } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -