Symfony Howto: Export tabular data to a csv file?
I have a mymodule/myaction that outputs csv (i.e. tabular data separated by ;). If I want to point to it and have my users open it with Excel as a spreadsheet, I need to do a few things:
- Add a special routing rule for mymodule/myaction which specifies a custom suffix.
export_excel: url: /export.csv param: {module: mymodule, action: myaction}
- If Apache's mod_rewrite is being used, add a new rule to the .htaccess file to ignore .csv files.
RewriteCond %{REQUEST_URI} !\.csv$
- Declare the mymodule/myaction view with a special content-type in the view.yml file.
myactionSuccess: has_layout: off http_metas: content-type: application/msexcel