Esempio n. 1
0
 /**
  * Creates a new Supplier model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Supplier();
     if (Yii::$app->request->isAjax) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return Json::encode([true, $model->name]);
         } else {
             return Json::encode([false, $model->errors]);
         }
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }