yii\rbac\ManagerInterface::createRole PHP Method

createRole() public method

Note that the newly created role is not added to the RBAC system yet. You must fill in the needed data and call ManagerInterface::add to add it to the system.
public createRole ( string $name ) : Role
$name string the role name
return Role the new Role object
    public function createRole($name);

Usage Example

示例#1
0
 /**
  * @param $userId
  */
 public static function initAdminAuth($userId)
 {
     self::enSureAuthManager();
     /**
      * @param                            $data
      * @param \yii\rbac\ManagerInterface $authManager
      * @param null                       $parent
      */
     function addItem($data, $authManager, $parent = null)
     {
         foreach ($data as $d) {
             $item = $authManager->createPermission($d['action']);
             $item->description = $d['name'];
             $authManager->add($item);
             $authManager->addChild($parent, $item);
             if (isset($d['children'])) {
                 addItem($d['children'], $authManager, $item);
             }
         }
     }
     \App::me()->db->transaction(function () use($userId) {
         self::cleanAll();
         $role = self::$_authManager->createRole('admin');
         $role->description = '超级管理员';
         self::$_authManager->add($role);
         addItem(self::all(), self::$_authManager, $role);
         self::$_authManager->assign($role, $userId);
     });
 }
All Usage Examples Of yii\rbac\ManagerInterface::createRole