Example #1
0
 public function actionUpdate($id, $type = null)
 {
     // Find Model
     $model = FormService::findById($id);
     // Update/Render if exist
     if (isset($model)) {
         $model->type = $type;
         $model->setScenario('update');
         if ($model->load(Yii::$app->request->post(), 'Form') && $model->validate()) {
             if (FormService::update($model)) {
                 $this->redirect($this->returnUrl);
             }
         }
         $templatesMap = TemplateService::getIdNameMapByType(CoreGlobal::TYPE_FORM);
         $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap);
         return $this->render('@cmsgears/module-core/admin/views/form/update', ['model' => $model, 'templatesMap' => $templatesMap, 'visibilityMap' => Form::$visibilityMap]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }