public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->renderAjax('_view', ['model' => $model]); } else { echo json_encode($model->firstErrors); } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @return Comment|null */ public function saveComment() { $comment = new Comment(); $comment->discussionID = $this->discussionID; $comment->message = $this->message; $comment->userID = $this->userID; $comment->email = $this->email; if ($comment->save()) { return $comment; } return null; }
public function actionCreate() { $model = new Comment(['scenario' => 'create']); Yii::$app->response->format = Response::FORMAT_JSON; if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($model->save(false)) { return $this->tree($model); } else { Yii::$app->response->setStatusCode(500); return Module::t('comment', 'FRONTEND_FLASH_FAIL_CREATE'); } } elseif (Yii::$app->request->isAjax) { Yii::$app->response->setStatusCode(400); return ActiveForm::validate($model); } } }