如何在symfony中导出为CSV文件中的数据

yipeiwu_com6年前PHP代码库
开始:
复制代码 代码如下:

public function executeRegistrantsToCsv(){

$id = $this->getRequestParameter('id');

$c = new Criteria();
$c->add(RegistrantPeer::EVENT_ID, $id);
$c->add(RegistrantPeer::STATUS, 1);
$this->aObjReg = RegistrantPeer::doSelect($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');

}

在模板registrantsToCsvSuccess.php:
复制代码 代码如下:

Title,Name,Email,Phone,Organisation,State,City,Country,Login Date,IpAddress
<? foreach($aObjReg as $r): ?>
<?= $r->getTitle() ?>,<?= $r->getName() ?>,<?= $r->getEmail() ?>,<?= $r->getPhone() ?>,<?= $r->getOrganisation() ?>,<?= $r->getState() ?>,<?= $r->getCity() ?>,<?= $r->getCountry() ?>,<?= $r->getLoginDate() ?>,<?= $r->getIpAddress() ?>,
<? endforeach ?>

in the templates/csv.php:
<?php echo $sf_data->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/

相关文章

PHP分页显示的方法分析【附PHP通用分页类】

本文实例讲述了PHP分页显示的方法。分享给大家供大家参考,具体如下: <?php header("content-type:text/html;charset=utf-...

ajax 的post方法实例(带循环)

ajax 的post方法实例(带循环)

用上循环就是为了在数据发送前进行合理的处理,解决在脚本语言对数据进行另外需求处理时出现的超时现象。处于对ajax认识未深,如有说得不对或不到位的,还请指教。     ajax中的po...

ThinkPHP like模糊查询,like多匹配查询,between查询,in查询,一般查询书写方法

ThinkPHP的数据库条件查询语句有字符串式,数组式书写方法 字符串式即是原生式,数组式查询语句因书写方式与特定字符的原因比较复杂,下面为大家例出了常用的ThinkPHP数组式查询语句...

php-fpm.conf配置文件中文说明详解及重要参数说明

php-fpm.conf配置文件中文说明详解及重要参数说明

php-fpm工作流程 php-fpm全名是PHP FastCGI进程管理器 php-fpm启动后会先读php.ini,然后再读相应的conf配置文件,conf配置可以覆盖php.ini...

PHP常见加密函数用法示例【crypt与md5】

PHP常见加密函数用法示例【crypt与md5】

本文实例讲述了PHP常见加密函数用法。分享给大家供大家参考,具体如下: 1.crypt()函数 crypt()函数用于返回使用DES、Blowfish或MD5算法加密过后的字符串,cry...