示例#1
0
 /**
  * Creates a new AuthItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AuthItem();
     if ($model->load(Yii::$app->request->post())) {
         $item = $this->model2Item($model, new Role());
         $this->auth->add($item);
         $groupName = YiiForum::getPostValue('AuthItem')['group'];
         $group = new Role();
         if ($groupName) {
             $group->name = $groupName;
             $this->auth->addChild($group, $item);
         } else {
             //判断角色根是否存在
             $rootRole = $this->auth->getRole('root_role');
             if (!$rootRole) {
                 $model2 = new AuthItem();
                 $model2->name = 'root_role';
                 $model2->description = '角色根';
                 $model2->rule_name = '';
                 $model2->data = '';
                 $item2 = $this->model2Item($model2, new Role());
                 $this->auth->add($item2);
             }
             $group->name = 'root_role';
             $this->auth->addChild($group, $item);
             AuthItem::createCachedRolesGroup();
         }
         return $this->redirect(['index']);
     } else {
         $locals = [];
         $locals['groups'] = YiiForum::getAppParam('cachedRolesGroup');
         $locals['model'] = $model;
         return $this->render('create', $locals);
     }
 }