Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 public function run()
 {
     //$comments = Comment::find()->where(['status' => Comment::STATUS_ACTIVE])->orderBy(['create_time' => SORT_DESC])->limit($this->maxComments)->all();
     $comments = BlogComment::findRecentComments($this->maxComments);
     return $this->render('recentComments', ['title' => $this->title, 'comments' => $comments]);
 }
Exemplo n.º 3
0
 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]);
 }
Exemplo n.º 4
0
 public function getComments()
 {
     return $this->hasMany(BlogComment::className(), ['post_id' => 'id']);
 }
Exemplo n.º 5
0
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogComment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }