Hello,
I’m having a problem with a pagination item.
I have a collection of items (programs) that can be filtered into three categories: Originals, Seasons, and Episodes. A filtered link would look like this
domain.test/programs/category:Episodes
So, I created a pagination for that collection and everything goes well, it works like this:
domain.test/programs/page:2
domain.test/programs/page:3
domain.test/programs/category:Episodes/page:2
domain.test/programs/category:Episodes/page:3
domain.test/programs/category:Seasons/page:2
…
Now, the problem comes whenever I refresh the page with a pagination number greater than “page:1” I get the following error:
Kirby\Exception\ErrorPageException thrown with message "Pagination page 2 does not exist, expected 1-1"
No matter if I have a category filter on or not, if I hit refresh or land on this page, this happens.
This is my controller:
<?php
return function($page) {
// fetch the basic set of pages
$programs = $page->children()->listed();
$episodes = $page->children()->listed()->children()->listed()->children()->listed()->sortBy('date','desc');
$seasons = $page->children()->listed()->children()->listed()->sortBy('date','desc');
// fetch all categories
$categories = $programs->pluck('categories', ',', true);
$categoriesnumber = $programs->pluck('categories', ',');
// add the category filter
if($category = urldecode(param('category'))) {
if ($category == 'Original') {
$programs = $programs->filterBy('original', true);
} elseif ($category == 'Temporadas') {
$programs = $seasons;
} elseif ($category == 'Episodios') {
$programs = $episodes;
} else{
$programs = $programs->filterBy('categories', $category, ',');
}
}
// add the tag filter
if($tag = urldecode(param('tag'))) {
$programs = $episodes->filterBy('tags', $tag, ',');
}
$categoriesnumber = array_count_values($categoriesnumber);
// apply pagination
$pagination = $programs->paginate(3); //This is number to test the pagination
return compact('programs', 'categories', 'category', 'categoriesnumber', 'tag', 'pagination', 'episodes', 'seasons');
};
Thanks in advance.
Edit:
Forgot to mention I’m using Fetch in Javascript to dynamically load everything. Could this be a problem?