function exportCSV() { global $i18n, $ClassDir; require_once 'File/CSV.php'; require_once $ClassDir . 'StringHelper.class.php'; $header = array("name", "gender", "birthday", "mobile", "phone", "office_phone", "fax", "addrees", "category", "email", "homepage"); $conf = array('fields' => count($header), 'sep' => ";", 'quote' => '"', 'header' => false, 'crlf' => "\r\n"); $filename = date("Y_m_d") . "_contact_export.csv"; $csv = new File_CSV(); // Write contact record $apf_contact = DB_DataObject::factory('ApfContact'); $apf_contact->orderBy('id desc'); $apf_contact->find(); while ($apf_contact->fetch()) { $row_data = array(); foreach ($header as $title) { $coloum_function = "get" . StringHelper::CamelCaseFromUnderscore($title); $row_data[] = $apf_contact->{$coloum_function}(); } $csv->append($row_data, $conf); } $csv->send($filename); exit; }