Answer the question
In order to leave comments, you need to log in
How to display pagination correctly now?
Good afternoon everyone.
Implemented the ability to add categories from the admin panel, and select a category when publishing a post.
Up to this point, the entries were displayed like this:
In Controllers:
public function actionPagestatji(){
$query = Statjiblog::find();
$pagination = new Pagination([
'defaultPageSize' => 5,
'totalCount' => $query->count()
]);
$Bgstatji = $query->orderBy(['id' => SORT_DESC])
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('pagestatji', [
'Bgstatji' => $query,
'active_page' => Yii::$app->request->get("page", 1),
'count_pages' => $pagination->getPageCount(),
'pagination' => $pagination
]);
}
use yii\widgets\LinkPager;
public function getCategorys()
{
return $this->hasOne(Category::className(),['id' => 'parent_category_id']);
}
public function actionPagestatji(){
$query = Statjiblog::find()->with('categorys')->each();
return $this->render('pagestatji', [
'Bgstatji' => $query
]);
}
Answer the question
In order to leave comments, you need to log in
Why did you change the action code? Everything was correct. Just had to replace
:$query = Statjiblog::find()->with('categorys');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question