如何在symfony中導(dǎo)出為CSV文件中的數(shù)據(jù)
更新時(shí)間:2011年10月06日 11:13:31 作者:
如果您需要在symfony中將數(shù)據(jù)庫中的數(shù)據(jù)導(dǎo)出為CSV文件,試試這個(gè)
開始:
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/
復(fù)制代碼 代碼如下:
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:
復(fù)制代碼 代碼如下:
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/
您可能感興趣的文章:
- Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法
- Symfony數(shù)據(jù)校驗(yàn)方法實(shí)例分析
- Symfony2實(shí)現(xiàn)在controller中獲取url的方法
- Symfony2框架學(xué)習(xí)筆記之表單用法詳解
- Symfony2學(xué)習(xí)筆記之系統(tǒng)路由詳解
- Symfony2學(xué)習(xí)筆記之控制器用法詳解
- Symfony2學(xué)習(xí)筆記之模板用法詳解
- Symfony2安裝第三方Bundles實(shí)例詳解
- Symfony2 session用法實(shí)例分析
- 高性能PHP框架Symfony2經(jīng)典入門教程
- Symfony2實(shí)現(xiàn)從數(shù)據(jù)庫獲取數(shù)據(jù)的方法小結(jié)
相關(guān)文章
php文章內(nèi)容分頁并生成相應(yīng)的htm靜態(tài)頁面代碼
php 文章內(nèi)容分頁并生成對應(yīng)的htm靜態(tài)文件實(shí)例代碼,一般主要用戶長文件分頁。2010-06-06php實(shí)現(xiàn)給圖片加灰色半透明效果的方法
這篇文章主要介紹了php實(shí)現(xiàn)給圖片加灰色半透明效果的方法,涉及對圖像的操作,是非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10PHP編程實(shí)現(xiàn)多維數(shù)組按照某個(gè)鍵值排序的方法小結(jié)【2種方法】
這篇文章主要介紹了PHP編程實(shí)現(xiàn)多維數(shù)組按照某個(gè)鍵值排序的方法,結(jié)合實(shí)例形式分析了array_multisort和array_sort 2種排序操作方法,需要的朋友可以參考下2017-04-04Ubuntu中支持PHP5與PHP7雙版本的簡單實(shí)現(xiàn)
這篇文章主要給大家介紹了關(guān)于Ubuntu中支持PHP5與PHP7雙版本的簡單實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),這個(gè)方法也非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08