Hi
I’m trying to apply pagination to results from a database. I’ve managed to connect to the database, display the results, and limit the number of items displayed. However when it comes to displaying the page links, I get the following error ‘Call to undefined method Kirby\Toolkit\Pagination::nextPageURL()’.
This is my controller
return function($kirby, $site, $pages, $page) {
$shared = $kirby->controller('site' , compact('page', 'pages', 'site', 'kirby'));
$poruke = Db::select('smsporuke', ['Drzava', 'Datum', 'Broj', 'Poruka'], null, 'Datum DESC', 0, 30);
// apply pagination
$poruke = $poruke->paginate(20);
$pagination = $poruke->pagination();
return A::merge($shared , compact('poruke', 'pagination'));
and this is my template
<?php foreach ($poruke as $poruka): ?>
<p class='mb-2'><strong>Drzava:</strong> <?= $poruka->Drzava() ?> - <strong>Datum:</strong> <?= $poruka->Datum() ?> <strong>Broj:</strong> <?= $poruka->Broj() ?> - <strong>Poruka:</strong> <?= $poruka->Poruka() ?></p>
<?php endforeach ?>
<?php if($poruke->pagination()->hasPages()): ?>
<nav class="pagination">
<?php if($poruke->pagination()->hasNextPage()): ?>
<a class="next" href="<?php echo $poruke->pagination()->nextPageURL() ?>">‹ older posts</a>
<?php endif ?>
<?php if($poruke->pagination()->hasPrevPage()): ?>
<a class="prev" href="<?php echo $poruke->pagination()->prevPageURL() ?>">newer posts ›</a>
<?php endif ?>
</nav>
<?php endif ?>
Can anyone spot the mistake? I’m using the same pagination code on my blog, and it works fine.