Welcome Guest, Not a member yet? Register   Sign In
Pagination Issue
#1

Hi,

When using the Pager service to create manual pagination links, it doesn't seem to recognise the URL segment when you use setPath() with it. For example:

PHP Code:
$pager = \Config\Services::pager();
$pager->setPath('page''my-group');
$links $pager->makeLinks($page$perPage$total'bootstrap'2'my-group'); 

It creates the links all well, but when moving to page 2 or 3, the links still show as being on page 1 (i.e. not recognising the Segment in the url).

My url is like: mysite.com/page/3

So I'm getting segment (2).

I need to use setPath() so that the links include the "page" part in the URL as by default the homepage is just mysite.com.

If I take a look at the Pager.php code, I can see that

PHP Code:
protected function ensureGroup(string $group, ?int $perPage null)
    {
        if (
array_key_exists($group$this->groups)) {
            return;
        }
... 

returns after setPath has been called. So when makeLinks() is called, the calculateCurrentPage() doesn't update the current page. If I comment out the // return; it starts to work perfectly.

Not sure if this is a bug or if I'm just using the Pager service wrong.
Reply
#2

This is a bug.
I sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/5803

Workround:
PHP Code:
$pager = \Config\Services::pager();
$pager->setSegment(2);
$pager->setPath('foo');
echo 
$pager->makeLinks($page10100'default_full'); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB