exporting csv in zend framework

11,459

Solution 1

To address your points in order

  1. There is not a component in the Zend Framework that will generate and dispose of CSV files.

  2. Your controller should just collect request parameters (i.e. date ranges from point 3) and initiate a response. I would create another class which can generate a CSV and then use this Controller Action Helper, SendFile to actually send the CSV file as a download.

  3. Have your controller receive the request parameters using a form. Generate a CSV using your class (point 2) and then use the helper to send the response.

For generating CSV files it's recommended to use fputcsv rather than building strings yourself.

Solution 2

Here is a Zend Framework Action Helper - may be helpful. Note the site and code comments are in German. http://blog.abmeier.de/zend-csv-action-helper

Share:
11,459
Awais Qarni
Author by

Awais Qarni

Full stack web developer having experience in multiple technologies and frameworks including PHP (Zend, Laravel, CakePHP), Ruby (ROR), Javascript (jQuery, Backbone.JS, Ember.JS).

Updated on June 04, 2022

Comments

  • Awais Qarni
    Awais Qarni almost 2 years

    I know how to export a csv file in php. Now I want to do this task in zendframe work.

    1 I want to know is there any built in functionality that zend provides for this purposes or we have to write the same code that we use in simple php?

    2 If I have to use same code then where should I put that whether in model or controller?

    3 I have a view where user can select start date, last date and user andthen press enter. On the basis of that selection I want to exprot csv file.

    Any one guide me how to accomplish this task