public function run()
 {
     $id = null;
     $modelClass = $this->modelClass;
     /** @var yii\db\BaseActiveRecord $model */
     $model = new $modelClass(['scenario' => $this->scenario]);
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id, null, ['newModel' => $model]);
     }
     $session = Yii::$app->getSession();
     $successMessage = $session->getFlash('success');
     $errorMessage = $session->getFlash('error');
     $request = Yii::$app->getRequest();
     if ($request->getIsPost()) {
         $model->load($request->getBodyParams());
         // validation
         if ($request->getIsAjax() && $request->getQueryParam('validation')) {
             Yii::$app->getResponse()->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         // processing
         $saved = $model->validate() && $model->save();
         if ($saved) {
             $id = ModelHelper::getPrimaryKey($model);
             $successMessage = Yii::t('mozayka', 'Record "{record}" has been successfully saved.', ['record' => ModelHelper::getDisplayField($model)]);
             if (!$request->getIsAjax()) {
                 $session->setFlash('success', $successMessage);
                 if (ModelHelper::canUpdate($model)) {
                     $url = ['update-form', 'id' => $id];
                 } elseif (ModelHelper::canRead($model)) {
                     $url = ['read-form', 'id' => $id];
                 } elseif (ModelHelper::canList($modelClass)) {
                     $url = ['list'];
                 } else {
                     $url = Yii::$app->getHomeUrl();
                 }
                 return $this->controller->redirect($url);
             }
         } else {
             ModelHelper::log($model);
             $errorMessage = Yii::t('mozayka', 'Record "{record}" has not been saved.', ['record' => ModelHelper::getDisplayField($model)]);
         }
         if ($request->getIsAjax()) {
             Yii::$app->getResponse()->format = Response::FORMAT_JSON;
             return ['ok' => $saved, 'message' => $saved ? $successMessage : $errorMessage, 'id' => $saved ? $id : false];
         }
     }
     // rendering
     $viewParams = ['canList' => ModelHelper::canList($modelClass), 'pluralHumanName' => ModelHelper::pluralHumanName($modelClass), 'successMessage' => $successMessage, 'errorMessage' => $errorMessage, 'model' => $model, 'fields' => $this->prepareFields($model), 'formClass' => $this->formClass, 'formConfig' => array_merge($this->formConfig, ['validationUrl' => [$this->id, 'validation' => 1]])];
     if ($request->getIsAjax()) {
         return $this->controller->renderPartial($this->view, $viewParams);
     } else {
         return $this->controller->render($this->view, $viewParams);
     }
 }
 public function run($id = null)
 {
     //$modelClass = $this->modelClass;
     /** @var yii\db\BaseActiveRecord $model */
     $model = $this->findModel($id);
     if (is_null($id)) {
         $id = ModelHelper::getPrimaryKey($model);
     }
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id, $model, ['id' => $id]);
     }
     return __METHOD__;
 }
 public function run($id = null)
 {
     $modelClass = $this->modelClass;
     /** @var yii\db\BaseActiveRecord $model */
     $model = $this->findModel($id);
     if (is_null($id)) {
         $id = ModelHelper::getPrimaryKey($model);
     }
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id, $model, ['id' => $id]);
     }
     // rendering
     $viewParams = ['canList' => ModelHelper::canList($modelClass), 'pluralHumanName' => ModelHelper::pluralHumanName($modelClass), 'model' => $model, 'id' => $id, 'displayField' => ModelHelper::getDisplayField($model), 'fields' => $this->prepareFields($model), 'formClass' => $this->formClass, 'formConfig' => array_merge($this->formConfig, ['readOnly' => true])];
     if (Yii::$app->getRequest()->getIsAjax()) {
         return $this->controller->renderPartial($this->view, $viewParams);
     } else {
         return $this->controller->render($this->view, $viewParams);
     }
 }