Exemplo n.º 1
0
 /**
  * 创建新评论
  * @param $topic
  * @return Comment
  */
 protected function newComment(Topic $topic)
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post())) {
         $model->author_id = Yii::$app->user->id;
         if ($topic->addComment($model, true)) {
             $this->flash('发表评论成功!', 'success');
             Yii::$app->end(0, $this->refresh());
         }
     }
     return $model;
 }