hryamzik
hryamzik

Reputation: 995

Cakephp: iterate through pages in a custom view

I have a view with several megabytes of data and I expect it to grow radically. Controller index function is implemented in a default way, with pagination. I would like to export this view to a csv without making much changes to the controller ( I'm fine to define header rows and rows to be included in a CSV but not to remove pagination as it brakes the html representation ).

The idea is simple: render csv view template, change the page, render another one. But how can I change current pagination settings in a custom view?

PS: I did take a look at the csv plugin. It doesn't work with pagination so I get out of the memory limits, it also creates a tmp file, I prefer to stream content on the fly.

Upvotes: 1

Views: 102

Answers (1)

floriank
floriank

Reputation: 25698

I wouldn't use the paginator here, just get the total amount of records then do a while() loop and fetch the data in batches to avoid memory limitations. And send it as it comes from the DB directly to the client. Use the HTTP Client that comes with CakePHP and set the proper header properties.

See these two answers how to send it as stream:

Upvotes: 1

Related Questions