/** * Displays page where one can edit comment chosen by id * @param $id * @return string */ public function actionEdit($id) { $id = Yii::$app->request->get('id'); // Checking if line with this id exists $check_id = Comment::find()->select(['comment_writer'])->where(['comment_id' => $id])->one(); if ($check_id != null) { $comment = new Comment(); $comment_to_update = $comment->findModel($id); $commentForm = new CommentUpdateForm($id, $comment_to_update); if ($commentForm->load(Yii::$app->request->post()) && $commentForm->updateComment($id)) { Yii::$app->session->setFlash('messageUpdated'); $this->redirect(Yii::$app->getUrlManager()->createUrl('comment/view')); } else { return $this->render('edit', ['commentForm' => $commentForm]); } } else { $this->redirect(Yii::$app->getUrlManager()->createUrl('comment/view')); } }