Ejemplo n.º 1
0
 public function actionCreate()
 {
     $model = new AuthItem();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $otherPermission = Yii::$app->request->post('otherpermission');
             $otherRole = Yii::$app->request->post('otherrole');
             $auth = Yii::$app->authManager;
             $role = $auth->createRole($model->name);
             $role->description = $model->description;
             $auth->add($role);
             if (!empty($otherPermission) && is_array($otherPermission)) {
                 foreach ($otherPermission as $permission) {
                     $child_permission = $auth->getPermission($permission);
                     if (!empty($child_permission)) {
                         $auth->addChild($role, $child_permission);
                     }
                 }
             }
             if (!empty($otherRole) && is_array($otherRole)) {
                 foreach ($otherRole as $therole) {
                     $child_role = $auth->getRole($therole);
                     if (!empty($child_role)) {
                         $auth->addChild($role, $child_role);
                     }
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data role has been successfully saved'));
             return $this->redirect(['create']);
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data role failed to save'));
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 2
0
 public function actionCreate()
 {
     $model = new AuthItem();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $parents = Yii::$app->request->post('parent');
             $auth = Yii::$app->authManager;
             $permission = $auth->createPermission($model->name);
             $permission->description = $model->description;
             $auth->add($permission);
             if (!empty($parents) && is_array($parents)) {
                 foreach ($parents as $parent) {
                     $child_permission = $auth->getPermission($parent);
                     if (!empty($child_permission)) {
                         $auth->addChild($permission, $child_permission);
                     }
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data permission has been successfully saved'));
             return $this->redirect(['create']);
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data permission failed to save'));
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 3
0
 public function actionCreate()
 {
     $model = new AuthItem();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $auth = Yii::$app->authManager;
             $permission = $auth->createPermission($model->name);
             $permission->description = $model->description;
             $auth->add($permission);
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data route has been successfully saved'));
             return $this->redirect(['create']);
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data route failed to save'));
         }
     }
     return $this->render('create', ['model' => $model]);
 }