Hello,
I'm trying to implement a pagination in my view but when I call the setSurroundCount function it gives me an error "Call to undefined method CodeIgniter\Pager\Pager::setSurroundCount() "
Does someone knows why ?
Here is my controller :
PHP Code:
function index($limit=100) {
// library('pagination');
$model = new \App\Models\TransactionModel();
$data = [
'title' => "Transactions",
'transactionsHTMLTable' => $this->formatTransactionsAsHTMLTable($model->paginate($limit)),
'pager' => $model->pager
];
// $data["transactionsHTMLTable"] = $this->formatTransactionsAsHTMLTable($model->transactions($limit, $offset));
echo view('top', $data);
echo view('transactions', $data);
echo view('bottom');
}
Here is my view ;
PHP Code:
<h3>Transactions</h3>
<?php
echo $transactionsHTMLTable;
// echo $pager->links();
$pager->setSurroundCount(2);
?>
<?php ?>
<nav aria-label="Page navigation">
<ul class="pagination">
<?php if ($pager->hasPrevious()) : ?>
<li>
<a href="<?= $pager->getFirst() ?>" aria-label="First">
<span aria-hidden="true">First</span>
</a>
</li>
<li>
<a href="<?= $pager->getPrevious() ?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<?php endif ?>
<?php foreach ($pager->links() as $link) : ?>
<li <?= $link['active'] ? 'class="active"' : '' ?>>
<a href="<?= $link['uri'] ?>">
<?= $link['title'] ?>
</a>
</li>
<?php endforeach ?>
<?php if ($pager->hasNext()) : ?>
<li>
<a href="<?= $pager->getNext() ?>" aria-label="Previous">
<span aria-hidden="true">»</span>
</a>
</li>
<li>
<a href="<?= $pager->getLast() ?>" aria-label="Last">
<span aria-hidden="true">Last</span>
</a>
</li>
<?php endif ?>
</ul>
</nav>
I took everything from the Codeigniter 4 documentation.
If I echo $pager->links() it works. So the $pager is here but the functions setSurroundCount getFirst, getNext, ... doesn't work.
Can someone help me ?