Issue
It seems that the standard pagination component in CakePHP 3 only allows the pagination of database queries. How can I adjust/overwrite pagination in order to display pagination of an array of data?
Solution
you can use Collection to manipulate array data http://book.cakephp.org/3.0/en/core-libraries/collections.html
Cake\Collection\Collection::take(int $size, int $from)
Whenever you want to take a slice of a collection use the take() function, it will create a new collection with at most the number of values you specify in the first argument, starting from the position passed in the second argument:
$topFive = $collection->take(5); // Take 5 data from the collection starting from position 4 $nextTopFive = $collection->sortBy('age')->take(5, 4);
Positions are zero-based, therefore the first position number is 0.
Answered By - Yosi Azwan
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.