/** * Creates a new Comments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comments(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->idcomments]); } else { return $this->render('create', ['model' => $model]); } }
public function init() { parent::init(); $model = new Comments(); if ($this->class_name != null) { $model->class_name = $this->class_name; } if ($this->item_id != null) { $model->item_id = $this->item_id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { } }
public function actionComment() { $frm = new Comments(); if ($frm->load(Yii::$app->request->post())) { //TODO: this is considered as given $frm->idtodo = 1; $frm->iduser = Yii::$app->user->id; if ($frm->save()) { echo "success"; } else { print_r($frm->getErrors()); } } }
public function actionSave() { $comment = new Comments(); if (Yii::$app->request->isPost) { $comment->text = Yii::$app->request->post('text'); $comment->user_id = Yii::$app->user->id; if ($comment->save()) { return $this->redirect('/user/profile'); } else { throw new ForbiddenHttpException('Ошибка сохранения комментария!', 404); } } else { return $this->goHome(); } }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function addComment() { try { $comments = new Comments(); $comments->author = $this->author; $comments->content = $this->content; $comments->created = date('Y-m-d'); $comments->updated = null; $comments->article_id = $this->article_id; $comments->status = 0; $comments->save(); } catch (ErrorException $e) { return false; } return true; }
/** * Creates a new Comments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comments(); $model->load(Yii::$app->request->post()) && $model->save(); return $this->redirect(['post/view', 'id' => $model->id_post]); }