public function actionCategory($id) { $query = News::find()->select(['news.id', 'news.title as n_title', 'news.text', 'news.date', 'categories.title as c_title'])->leftJoin('categories', 'categories.id = news.category_id')->where(['news.category_id' => $id])->orderBy('news.date DESC'); $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => 5]); $news = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); return $this->render('year', ['news' => $news, 'pages' => $pages]); }
public function actionAllNews() { $news = News::find()->orderBy('dt_add DESC'); $countQuery = clone $news; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 2]); $news = $news->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('all', ['news' => $news, 'pages' => $pages]); }