Welcome Guest, Not a member yet? Register   Sign In
Pagination problem 4.0.4
(This post was last modified: 09-01-2020, 08:43 AM by Gary.)

I'm having a hiccup with latest builds of CI (4.0.4 as well as the last few dev builds that I've subsequently installed, after seeing there's been a few problems discussed pre-4.0.4 and also a current (still-outstanding) bug report related to pagination, though it seems to be parked, waiting for more info: https://github.com/codeigniter4/CodeIgni...ssues/3164).

Relevant points:

1) I'm using manual pagination in a manner similar to what's outlined here: https://codeigniter.com/user_guide/libra...pagination
2) My code has been working without (observed) problems for a while (besides for a recently discovered pre-upgrade problem where some of the links generated on the last page were repeats of previously listed items- which triggered the investigation into pagination issues and my upgrade to the official 4.0.4).  This point is for information only, and may well be a problem with my code [update: this appears to be a separate issue to do with the $builder->whereIn() function, as discussed here: https://forum.codeigniter.com/thread-77429.html].
3) Subsequent to upgrading to 4.0.4 (and one of recent dev builds), the auto-generated links to other pages has been broken.

If I change this bit of the store() routine in the system's Pager.php -

if ($segment > 0 && $this->groups[$group]['currentPage'] > 0)
  $page = $this->groups[$group]['currentPage'];
$perPage = $perPage ?? $this->config->perPage;
$pageCount = (int)ceil($total / $perPage);
$this->groups[$group]['currentPage'] = $page > $pageCount ? $pageCount : $page;

// if ($segment > 0 && $this->groups[$group]['currentPage'] > 0)
// {
//    $page = $this->groups[$group]['currentPage'];
// }
$perPage = $perPage ?? $this->config->perPage;
$pageCount = (int)ceil($total / $perPage);
$page = $page > $pageCount ? $pageCount : $page;
$this->groups[$group]['currentPage'] = $page > $pageCount ? $pageCount : $page;

then it seems to work again...

I did gloss over the documentation on Paging, and I don't notice anything that's changed in the Pagination for 4.0.4... so did I miss something, is there likely a bug in my code, or has a bug been introduced into the CI pagination code?

(This post was last modified: 09-06-2020, 04:04 AM by Gary.)

Just a brief update on this one...

I find this problem appears to be a fallout of an issue discussed in one of my other posts regarding (manual) pagination in 4.0.4:

The system's Model.php paginate() function invokes an instance of the Pager service in a NON-SHARED mode (which seems to be a mistaken choice (?)).

When invoked in this manner, it appears that call/s to the Pager's store() routine see different parameters to what the Model's instance of store() has just set: store() is invoked by Model's paginate() and also, a moment later, in the Pager's makeLinks() routine. When these two calls see different parameters, it causes the links that are generated by makeLinks() - which would appear to be typically called immediately after the paginate() function if one is doing manual pagination() - to be fished (it looses which page is current).

So, to fix this problem, I've found that the system's Pager.php (mentioned in the post above) should be left as it was... and that the source of the hiccup is actually in paginate() in Model.php, which should simply have:
$pager = \Config\Services::pager(null, null, false);
changed to:
$pager = \Config\Services::pager(null, null, true);

Can someone please confirm this, or, alternatively explain why the Model's paginate() uses a non-shared instance of the pager service (and then also how best to get CI's manual pagination to work in 4.0.4)?


Additional note: there is already the $group parameter that 'separates' calls to the store() routine.

Theme © iAndrew 2016 - Forum software by © MyBB