示例#1
0
 public function actionUpdate($id, $returnUrl, $type = null)
 {
     // Find Model
     $model = RoleService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $model->type = $type;
         $model->setScenario('update');
         if ($model->load(Yii::$app->request->post(), 'Role') && $model->validate()) {
             if (RoleService::update($model)) {
                 $binder = new Binder();
                 $binder->binderId = $model->id;
                 $binder->load(Yii::$app->request->post(), 'Binder');
                 RoleService::bindPermissions($binder);
                 $this->redirect($this->returnUrl);
             }
         }
         $permissions = PermissionService::getIdNameListByType($type);
         return $this->render('update', ['model' => $model, 'permissions' => $permissions]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }