示例#1
0
 /**
  * Creates a new Relation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Relation();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'role' => $model->role, 'permission' => $model->permission]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 public function actionPermission($role)
 {
     $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all();
     if (\Yii::$app->request->isPost) {
         var_dump(LuLu::getPostValue('Permission'));
         $selectedPermissions = LuLu::getPostValue('Permission');
         $keys = array_keys($selectedPermissions);
         Relation::deleteAll(['role' => $role]);
         foreach ($selectedPermissions as $key => $value) {
             $newRelation = new Relation();
             $newRelation->role = $role;
             $newRelation->permission = $key;
             $newRelation->value = is_string($value) ? $value : implode(',', $value);
             $newRelation->save();
         }
         return $this->redirect(['index', 'role' => $role]);
     }
     $allPermissions = Permission::findAll();
     return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions]);
 }