/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); 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 News model. * @return mixed */ public function actionCreate() { $model = new News(); if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); Yii::$app->response->format = 'json'; if ($model->save()) { return Yii::$app->params['response']['success']; } else { return ActiveForm::validate($model); } } else { return $this->renderAjax('create', ['model' => $model, 'statuses' => Yii::$app->current->getStatuses()]); } }