CodeIgniter Forums
Pagination Problems - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Pagination Problems (/showthread.php?tid=77644)

Pages: 1 2

RE: Pagination Problems - Gary - 10-02-2020

Ok, the example code makes it clearer, thank you InsiteFX.

It would appear that we're talking about different aspects of the pagination functionality... displaying an array of material from the Controller is one thing, which clearly your example does, but this wasn't my problem... my headache was in generating the (raw) content of the data records to be displayed.

In my Model, a load of geographic data is recovered for each user request (there are many (perhaps two dozen) such geographic points associated with every one of potentially tens of thousands of database records recovered in each query). The data needed to be processed and filtered according to the user's selections (each involving many calculations done on each of these individual geographic points- for example to adjust for the curvature of the earth- and which also use data recovered in sub-queries from other database tables).

Many of the recovered records from my database are thrown out in the filtering process (based on selections made by users) and the ones that remain are no longer the raw database record- I essentially end up with an array of related, but totally different data that then needed to be displayed in a paged format.

Dreaming up a query that could have been used to pull the data from the database and do all the required processing on each of the points in each of the required records and then throw out the ones that don’t match the criteria after the processing (the stage shown in your example’s Model code) in such a manner that it could be used in a chained query looked like a pretty tall order to me (perhaps impossible ?)... which is why I was trying to display and paginate an array of (custom) data.

RE: Pagination Problems - heriniaina - 06-12-2022

Just for the record if you have already solved it.
In Ci4 that's the use of the callbacks in models. And what you need here is afterFind
So in the model you put something like...
PHP Code:
protected $afterFind = ['filterResults']; 

Then you create the method in the same model

PHP Code:
protected function filterResults($eventData)
$eventData = ['method', 'limit', 'offset', 'data', 'singleton']

switch ($eventData['method']) {
                foreach (
$eventData['data'] as $row) {

//modify the result here in case of findAll
$rows[] = $row;

                return [
'data' => $rows];


$row $eventData['data'];

// modify the result here in case of find
return ['data' => $row];


With that the paginate still work.

RE: Pagination Problems - Gary - 06-23-2022

Thanks heriniaina.