getPermissionsByRole() public method

Returns all permissions that the specified role represents.
public getPermissionsByRole ( string $roleName ) : Permission[]
$roleName string the role name
return Permission[] all permissions that the role represents. The array is indexed by the permission names.
コード例 #1
0
 public function testGetPermissionsByRole()
 {
     $this->prepareData();
     $permissions = $this->auth->getPermissionsByRole('admin');
     $expectedPermissions = ['createPost', 'updatePost', 'readPost', 'updateAnyPost'];
     $this->assertEquals(count($expectedPermissions), count($permissions));
     foreach ($expectedPermissions as $permissionName) {
         $this->assertTrue($permissions[$permissionName] instanceof Permission);
     }
 }
コード例 #2
0
ファイル: RoleForm.php プロジェクト: yujin1st/yii2-user
 /**
  * @param Role $role
  */
 public function setRole($role)
 {
     $this->_role = $role;
     $this->name = $role->name;
     $this->oldName = $role->name;
     $this->description = $role->description;
     if (!$this->isNewRecord) {
         $permissions = $this->auth->getPermissionsByRole($role->name);
         foreach ($permissions as $permission) {
             $this->actions[] = $permission->name;
         }
     }
 }
コード例 #3
0
ファイル: RoleController.php プロジェクト: wsdslm/yii2-rbac
 public function actionChild($name)
 {
     $dataProvider = new ArrayDataProvider(['allModels' => $this->auth->getPermissionsByRole($name)]);
     return $this->render('assign', ['dataProvider' => $dataProvider]);
 }