public function run() { $view = $this->renderOnlyComments ? 'onlyComments' : 'comments'; $this->registerJs(); $dataProvider = new ActiveDataProvider(['query' => Comment::find(['page_id' => $this->pageID])->joinWith('user')->orderBy('date'), 'pagination' => false]); echo $this->render($view, ['comments' => $dataProvider]); }
/** * @param $body * @param $page_id * @return mixed */ private function _addComment($body, $page_id) { $comment = new Comment(); $comment->body = $body; $comment->date = time(); $comment->page_id = $page_id; $comment->user_id = Yii::$app->user->id; return $comment->save(); }