Answer the question
In order to leave comments, you need to log in
Yii how to set multiple roles?
due to specifics, I want to assign several roles. It is clear that there will be a many-to-many relationship.
I feel that I need to edit here
class WebUser extends CWebUser {
private $_model = null;
function getRole() {
if($user = $this->getModel()){
// в таблице User есть поле role
//return $user->id_role;
return Role::model()->findByPk($user->id_role)->name;
}
}
private function getModel(){
if (!$this->isGuest && $this->_model === null){
$this->_model = User::model()->findByPk($this->id, array('select' => 'id_role'));
}
return $this->_model;
}
}
Answer the question
In order to leave comments, you need to log in
You first cut RBAC to one role and then you are interested in how to return everything back) Read the documentation:
here, in my opinion , habrahabr.ru/post/235485 is more correct , do not look at yii2, the approach remained the same, only bizrule in yii1 were stored as strings, and in yii2
you can read this class
here yiiframework.ru/doc/cookbook/ru/access.rbac.file blob/master/docs/g... again in terms of explaining how RBAC works
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question