示例#1
0
 /**
  * Добавление города
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new City();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             return 'success';
         } else {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->renderAjax('create', ['model' => $model]);
 }
示例#2
0
 /**
  * Добавление нового города из Кладр через Ajax
  * @return array
  */
 public function actionCityCreate()
 {
     $model = new City();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($model->save()) {
             return ['status' => 'success', 'id' => $model->id, 'name' => $model->name];
         } else {
             return $model->getFormattedError();
         }
     }
 }