Symfony How to export data in a CSV file in Symfony

Source: Internet
Author: User
Begin:

Copy the Code code as follows:


Public Function Executeregistrantstocsv () {
$id = $this->getrequestparameter (' id ');
$c = new Criteria ();
$c->add (registrantpeer::event_id, $id);
$c->add (Registrantpeer::status, 1);
$this->aobjreg = registrantpeer::d oselect ($c);
$this->forward404unless ($this->aobjreg);
$this->setlayout (' csv ');
$this->getresponse ()->clearhttpheaders ();
$this->getresponse ()->sethttpheader (' Content-type ', ' application/vnd.ms-excel ');
$this->getresponse ()->sethttpheader (' content-disposition ', ' attachment; filename=registrants_report_event_ ' . $id. '. csv ');
}


In the template registrantstocsvsuccess.php:

Copy the Code code as follows:


Title,name,email,phone,organisation,state,city,country,login date,ipaddress

GetTitle (), getName (), getemail ();, Getphone (),, getorganisation (),;, C6/>getstate (), getcity (), Getcountry (),, getlogindate (), getipaddress ()? ,


In the templates/csv.php:
Getraw (' sf_content ')?>
from:http://blog.baddog.net.au/sonius/steve-sonius/how-to-export-data-as-a-csv-file-in-symfony/
If it doesn ' t work, try This:http://blog.baddog.net.au/sonius/steve-sonius/ how-to-export-data-as-an-xls-or-csv-file-from-the-admin-generator-in-symfony-1-4/

The above describes how symfony in the Symfony to export the data in the CSV file, including the symfony aspect of the content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.