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