Welcome Guest, Not a member yet? Register   Sign In
Pagination : Call to undefined method setSurroundCount()
#1

(This post was last modified: 04-27-2020, 10:23 AM by David Goncalves.)

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">&laquo;</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">&raquo;</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 ?
Reply


Messages In This Thread
Pagination : Call to undefined method setSurroundCount() - by David Goncalves - 04-27-2020, 08:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB