Multiple Role

According to document Yii implements a General Hierarchical RBAC, following the NIST RBAC model.

NIST General Hierarchical model built on top of Flat RBAC + supporting role hierarchy.

So RBAC must support many-to-many user-role assignment.

How can I assign multiple role to a user? it’s seems impossible with Yii::$app->authManager->assign()

Thanks

Call: ->assign(‘role1’, $userID); ->assign(‘role2’, $userID); etc.

first parameter of assign() must be instance of Role I think :




public function assign($role, $userId)

    {

        if (!isset($this->items[$role->name])) {

            throw new InvalidParamException("Unknown role '{$role->name}'.");

...



in below example the user role is the last one.




$role1 = $auth->getRole('role1');

$role2 = $auth->getRole('role2');

$auth->assign($role1, 26);

$auth->assign($role2, 26);




result in assignments.php file is





<?php

return [

    26 => 'role2',

];




Hmm, that’s probably a bug. Can you add it to github? https://github.com/yiisoft/yii2/issues/new Thanks!

Reported here

Thanks

Fixed.