/** * 创建评论 * @param $id * @return PostComment|\yii\web\Response */ public function actionCreate($id) { $model = new PostComment(); if ($model->load(Yii::$app->request->post())) { $topService = new TopicService(); if (!$topService->filterContent($model->comment)) { $this->flash('回复内容请勿回复无意义的内容,如你想收藏或赞等功能,请直接操作这篇帖子。', 'warning'); return $this->redirect(['/topic/default/view', 'id' => $id]); } $model->user_id = Yii::$app->user->id; $model->post_id = $id; $model->ip = Yii::$app->getRequest()->getUserIP(); if ($model->save()) { $this->flash("评论成功", 'success'); } else { $this->flash(array_values($model->getFirstErrors())[0], 'warning'); } return $this->redirect(['/topic/default/view', 'id' => $id]); } return $model; }