Paginate Array Result on Cakephp 2.8.2

Hello everyone…

I am needing paginate a search result, the result comes from a search on multi TXT files, I have reviewed the manual “custom paginate” but I’m not getting that modification work…

i try this solution from stackoverflow (not work for me): [link to the post]
(http://stackoverflow.com/questions/17209716/cakephp-pass-a-array-to-paginate-new-model)

I have everything my result in structured array… but how to do pagination… ?

Thanks in advance!

I suspect this is somewhat difficult to do, since the Pagination component creates SQL queries to get the desired data. I don’t think it will work easily with simple text files. You could - in theory - create a new datasource and implement logic that would allow it to work with txt files like with regular models. But it’s probably fairly complicated and not worth the energy unless this is a really essential feature and you don’t mind putting some effort into it.

A simpler way would be to not use the CakePHP pagination and instead just pass a parameter that determines the current entries to be displayed (i.e. via array_slice) in the function you use to fetch the data.

But you probably wouldn’t be able to use the pagination helper, then. This might not be a problem at all if you want to use endless scroll, but if you want to use regular pagination, you’d probably have to create your own helper.

So yeah, as far as I know, there’s not really a readymade solution for this specific problem in CakePHP, as it’s a bit contrary to best practices. You may have to think a little outside the box to find an good solution.

By the way, have you considered importing the data from the text files to the database? In general, it’s not a good idea to have a lot of data in text files, certainly not so much that it would require pagination.

Oh, one final idea: If you use data from text files, you have to load them all at once anyway, so there’s no performance/memory benefit on the server side to paginate the results. With that in mind, maybe it would be best to load all the data at once and then use a jQuery Plugin to paginate it. Of course, this is only an option if the total amount of data isn’t ridiculously high.

1 Like

SOLVED!
Thanks Ali, I found a way to paginate any html table with javascript, very simple!

The site provides a CSS library, a library JQuery and JavaScript library, if you already have the data in html tables (as was my case) all that is needed is to add special tags: THEAD, TFOOT and TBODY, in the following link has an example that even allows you to filter the records.

that is all!

The site, the example and the libraries from here:
Alternative Paginations

Thanks, this is solved!