3

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

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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

2 Comments

You should put a note about the language of the page :-) I was quite shocked it wasn't in english :-) :-)
Dead link... :(
0

Building on regilero's answer for this question, I did come up with a Zend solution. Just use a complete query on the database itself:

$result = $this->_db->query(
     'SELECT * FROM `table_xy`'
    .'INTO OUTFILE \'tmp/outputfile.csv\''
    .'FIELDS TERMINATED BY \';\''
    .'ENCLOSED BY \'"\''
    .'LINES TERMINATED BY \'\\n\''
);

Just don't forget to set up the necessary privileges for that user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.