D
D
des1roer2015-04-28 17:12:14
Yii
des1roer, 2015-04-28 17:12:14

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;
    }
}

Or does it return an array anyway?
now done like this
des1roer.blogspot.ru/2015/03/yii-rbac.html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-06-04
@vyachin

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 question

Ask a Question

731 491 924 answers to any question