Hi!
Iβm trying to use mysite.com/blog/page/2
instead of mysite.com/blog/page:2
.
To do this, I have this route :
[
'pattern' => 'blog/page/(:num)',
'action' => function ($pagenum) {
return page('blog')->render([
'pagenum' => $pagenum
]);
}
]
My pagination :
<?php if($pagination->hasPrevPage()): ?>
<a href="<?= page('blog')->url() . "/page/" . $pagination->page() - 1 ?>">
β Previous posts
<?php var_dump($pagination->page()) ?>
</a>
<?php endif ?>
<?php if($pagination->hasNextPage()): ?>
<a href="<?= page('blog')->url() . "/page/" . $pagination->page() + 1 ?>">
Next posts β
</a>
<?php endif ?>
And in my controller :
$articles = $articles->paginate(10, intval($pagenum));
$pagination = $articles->pagination();
It work, but when you try to get a page that doesnβt exists, like mysite.com/blog/page/18
, the Pagination page 5 does not exist, expected 1-2
error occurs instead of a 404.
How can I prevent this?
Thanks!