newModel()->find()->orderBy('created_at desc')->with('article')->limit($limit)->all(); } public function getCommentCountByPeriod($startAt=null, $endAt=null) { $model = Comment::find(); if( $startAt != null && $endAt != null ){ $model->andWhere(["between", "created_at", $startAt, $endAt]); }else if ($startAt != null){ $model->andwhere([">", "created_at", $startAt]); } else if($endAt != null){ $model->andWhere(["<", "created_at", $endAt]); } return $model->count('id'); } }