PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] How to paginate an array

 January 26, 2022     cakephp, cakephp-3.0, pagination, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing