Cakephp: iterate through pages in a custom view - cakephp

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.

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:
send a file to client
PHP: stream remote pdf to client browser
Streaming a large file using PHP

Related

Azure App Logic - How to page files on blob storage

I have a blob with over 5000 files. Checking the documentation and limited by pagination this amount.
I'm trying to do a paging in the APP LOGIC but I'm not able to do this loop. When I get the PAGE MARKER it returns strange information and I don't understand how to put it in the loop
How do I adjust my code for looping and paging the data inside the BLOB?
I set up this stream to get the paging
I created a string variable to view the PAGINATION content
When I run app logic and parse the variable, it returns this weird content instead of pages 1, 2...
When I try to configure the loop to go through all the pages I don't know what to inform the counter and the variable paging marker. How should I configure this part?
Instead of #equals(body('Lists_blobs_(V2)')?['nextPageMarker'], '') use #equals(variables('pagination'), '').
Before the end of the Until loop, set the pagination variable to Next page marker from Lists blobs (V2) 2 (the action inside the loop).

CakePHP returning 502 when passing large dataset to the view

I am passing a large data set to a view (~3000 rows). The view then presents the data in a table.
This works locally, but returns a 502 in the server.
I am not using pagination for this particular query because the client wants the whole list in one go. Retrieving the results is actually working fine, I can stop the process and view the query results.
The issue comes from passing the large array to the view using set(): $this->set('data', $data);
If I comment this line, the process completes as expected (with no data to display obviously).
I tried saving the array in the session, and using this to render the table on the view. This works, but it crashes the Cake debugging plugin.
I also tried caching the data, and retrieving the data from the cache on the view. This also works.
What could cause the $this->set() to return a 502? Is there a setting I am missing to allow passing large dataset to the view?
Also, there is nothing relevant in the logs.
Thanks,

AngularJS dynamic table - RESTfull data

I have a big data portion that I would like to post in a table. However, the data should be sorted and paginated. I know I am able to pass the whole data to the client at once and then paginate it using angular, but this will be too slow. I prefer to pass the data page-by-page, so one the client want to open a page from a table to load the data for it.
Up until now I have created an API that returns me the data that I need, based on the page number and the number of rows on the page. However, I don't know how to use it with AngularJS.
Can you please help me?
It looks like a backend problem. If you are using a standard restful backend, use the limit/skip parameters, you can encapsulate into a paginate.
Example:
localhost:1337/dataTable?skip=0&limit=100
localhost:1337/dataTable?skip=100&limit=100
localhost:1337/dataTable?skip=200&limit=100
...
On the frontend use a table object like ng-Table, and use the pages to keep track of the offset, the page number and the total items available.
skip = (pagNum - 1 * pageSize)
limit = pageSize
Make your backend return you the page you want plus the available dataNumber so you can build the pages controller.
Documentation for skip/limit on sails
http://sailsjs.org/documentation/reference/waterline-orm/queries/limit
http://sailsjs.org/documentation/reference/waterline-orm/queries/skip
Best approach is to keep track of the limit and offset in your controller. Then when user selects new page (offset) or changes items per page (limit), update the corresponding values and use them to make a new http request.
You could call a function on ng-change of a dropdown and that drop down would contain values of page number and number of records to fetch. Or you can provide two text boxes one for page number other for number of records and keep a button and on its ng-click event that will take value of those text boxes and post to your server and bring back data based on new values in text boxes

Pyrocms Getting Values at front end

I am new to pyrocms.
How can I get database values on pages of pyrocms. In website of pyrocms I had created a listing page now I want to display database values from pyro database table.
I got your question, you want to create a listing on your front-end page for some database table values which you want to access through your custom module controller. there are many ways to get these values but the simplest way is to use ajax. you already have Jquery added in pyrocms so you can simply make a call to your controller method in ajax and get your required output as HTML and display it in the div element on your page.
$.ajax({
type:"POST",
url:"admin/your-controller-name/your-method-name",
success:function(html){
$('yourdiv').html(html);
}
})
In your controller create a method which get data from database and print it using echo create some listing table etc what you want.
i think you will get my point. if confuse then get back to me
You need to be more specific as PyroCMS has lots of components and each module (blogs, variables, widgets, file uploads etc.) uses specific tags you insert into the page. You may come across references to 'Lex' - that's the name of the parser used to display them.
Tags documentation
PyroCMS (the Professional edition) also has a feature called "Streams" which allows you to build custom databases and this in turn has it's own series of tags.

Recreate a form in CakePHP 1.3 from $this->data?

I've got a Cake application with a reports query interface, where the admin user can filter the data by various inputs in a form and the results are then displayed on the screen. I am looking for the simplest way to add a button which allows the user to download the results of this same query as CSV.
I'm sure I can create one for myself if I have to, but is there already a way to regenerate any given form based on $this->data? That way, I can just add .csv to the form action and use RequestHandler to choose the right output format.
[here take a look at the following...
instead of finding the data from Db you can simply pass $this->data to it.
take a look at follo
Exporting data to CSV the CakePHP way
I guess you have to replicate the function on your controller, one for generating the results on screen and another same function intended for csv, but on the function for csv it must have parameters which are similar to the values of $this->data. Use javascript to redirect on the function for csv.

Resources