/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlogComment::find(); $query->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'post_id' => $this->post_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
public function actionView() { if (Yii::$app->request->get('id') && Yii::$app->request->get('id') > 0) { $post = BlogPost::findOne(Yii::$app->request->get('id')); $post->updateCounters(['click' => 1]); $comments = BlogComment::find()->where(['post_id' => $post->id, 'status' => Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_ASC])->all(); $comment = $this->newComment($post); } else { $this->redirect(['blog']); } //var_dump($post->comments); return $this->render('view', ['post' => $post, 'comments' => $comments, 'comment' => $comment]); }