How can i do Pagination for the return Array of values instead of Object in Cakephp 3.x

Hi,
I want to Pagination(in Cakephp 3.x) for Array of values which return from cakephp model instead of Paginate Object.

Thanks,
Naresh KURUKUTI.

can’t you typecast the array to an object, paginate it then turn it back into an array?

Can you provide a bit of code to demonstrate what you have so far, with comments about where you want to go from there? I’m having a hard time picturing exactly what it is you’re trying to accomplish.

Hi EveryOne,
Here $results array data getting from find all query.

foreach ($results as $key => $val):
$installment_sum = 0;
foreach ($val[‘student_payment_plan’][‘student_payment_plan_installments_sum’] as $value):
$installment_sum = $installment_sum + $value[‘amount’];
endforeach;
if ($val[‘payments_sum’] <= $installment_sum) {
$results[$key][‘total_installment_amount’] = $installment_sum;
} else {
unset($results[$key]);
}
endforeach;

return $results;

So, Here i return the $results array from model control. In controller set like this
$this->set(‘student_over_due_report’, $this->paginate($student_over_due_report)); Then i getting error "Unable to locate an object compatible with paginate.
"

You aren’t showing how $student_over_due_report is being initialized. I’ll assume it’s from the return value of this function. Pagination does not deal with arrays, it deals with query objects. The goal is to read only the records that you will be displaying, not to read everything. So, either you need to come up with a way to build the query so that it does the “if” for you, or else use some other method, like the slice function of collections, to extract what you need.