Пример #1
0
 /**
  * Creates a new Package model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Package();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Package model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Package();
     $arr['Package'] = Yii::$app->request->post();
     if ($model->load($arr) && $model->save()) {
         Yii::$app->response->format = 'json';
         Yii::$app->response->setStatusCode(201);
         Yii::$app->response->data = $model;
         Yii::$app->response->send();
     } else {
         Yii::$app->response->format = 'json';
         Yii::$app->response->setStatusCode(400);
         Yii::$app->response->data = ['message' => 'Record cound\'t be saved'];
         Yii::$app->response->send();
     }
 }