0

I have built a report for an client account that shows payments and charges with totals. I am now adding an export button using the PHPExport module.

As I already built the data to display in the web report, it seems inefficient to build it again if the user wants to export it. So I am thinking of building the arrays ($header and $data) needed for the report at the same time as I build the report page to display in the browser.

In order to then have access to these arrays in my export function, which would be called by a form submit, I will need to store them in the database (is that right?). Then, if the user submits and export request, I retrieve the arrays and pass them to the phpexcel_export() function and Robert's your mother's brother.

When the user then navigates away from the report, I will need to tidy up, by which I mean delete the arrays from the database. Do I use the onBeforeUnload API to achieve this? It seems from the api page to be little used.

Or am I approaching this from the wrong angle? Is there another way to persist the arrays from producing the page to submitting the export request from the page?

  • It sounds like you could delete the data from the database when the user clicks the 'export' button and that is processed server side. Otherwise, you could store it in a cache table with an expiry timestamp to delete via cron / cache clear. – David Thomas Apr 2 '14 at 0:40
  • I thought about deleting the data on export, but then considered the case of a second request to export for whatever reason. Also, it is only an option to export, most times the user will simply look at the report online, so there will not always be a submit request. Are the variable_set() and variable_get() functions an option here to persist the $headers and $data variables?` Although I had also thought about an expiry date on the reports, so your cache suggestion is helpful, thanks. – NectarSoft Apr 2 '14 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.