public function run() { $commentForm = $this->createComment(); if (isset(Yii::$app->session['email']) && isset(Yii::$app->session['email'])) { $commentForm->email = Yii::$app->session['email']; $commentForm->username = Yii::$app->session['username']; } $comments = Comment::find()->where(['entity' => $this->entity, 'status' => 1])->tree(); echo $this->render('comments', compact('comments', 'commentForm')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find()->orderBy('created_at DESC'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'level' => $this->level, 'created_by' => $this->created_by, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function run() { $comments = Comment::find()->where(['status' => 1])->orderBy('created_at DESC')->limit(10)->all(); echo $this->render('last-comments', compact('comments')); }