如何在symfony中導出為CSV文件中的數(shù)據(jù)
更新時間:2011年10月06日 11:13:31 作者:
如果您需要在symfony中將數(shù)據(jù)庫中的數(shù)據(jù)導出為CSV文件,試試這個
開始:
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實現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法
- Symfony數(shù)據(jù)校驗方法實例分析
- Symfony2實現(xiàn)在controller中獲取url的方法
- Symfony2框架學習筆記之表單用法詳解
- Symfony2學習筆記之系統(tǒng)路由詳解
- Symfony2學習筆記之控制器用法詳解
- Symfony2學習筆記之模板用法詳解
- Symfony2安裝第三方Bundles實例詳解
- Symfony2 session用法實例分析
- 高性能PHP框架Symfony2經(jīng)典入門教程
- Symfony2實現(xiàn)從數(shù)據(jù)庫獲取數(shù)據(jù)的方法小結(jié)
相關(guān)文章
Zend Studio for Eclipse的java.lang.NullPointerException錯誤的解決方
Zend Studio for Eclipse 6.x 可以算得上是最好的PHP的IDE了.2008-12-12
PHP將HTML轉(zhuǎn)換成文本的實現(xiàn)代碼
這篇文章主要介紹了PHP將HTML轉(zhuǎn)換成文本的實現(xiàn)代碼,需要的朋友可以參考下2015-01-01

