在Symfony Admin中多次连接到Excel的Mysql查询

我创build了一个很好的注册前端应用程序,用于注册一个事件的新用户。

我现在正在创build一个来自pipe理员生成的后端的所有与会者的Excel导出。

目前我写了一些SQL,给了我需要的确切表格:

select CONCAT(p.first_name,' ',p.last_name) as "Registered User", p.email_address as "Register Email", p.country as "Register Country", t.name as "Attendee Type" , CONCAT(a.first_name, ' ',a.last_name) as "Attendee", CONCAT(disc.name, ' ',disc.sex) as "Discipline", CONCAT(divi.category, ' ', divi.weight) as "Division", a.sex as "Sex", a.club_name as "Club Name", a.accomodation as "Accommodation", a.`sharing_with1` as "Sharing With A", a.`sharing_with2` as "Sharing With B", a.`flight_number` as "Flight Number", a.`flight_datetime` as "Flight Date", a.`flight_time` as "Flight Time", if(a.visa > 0, 'Yes', 'No') as "Visa", a.dob as "Date of Birth", a.passport as "Passport", a.`expiry_date` as "Passport Expiry" from `profile` p, `type` t, `attendee` AS a LEFT JOIN `division` AS divi ON (a.division_id = `divi`.id) LEFT JOIN discipline AS disc ON (divi.discipline_id = disc.id) where a.profile_id = p.id AND a.type_id = t.id 

正如你所看到的,有几个标准和外部连接。

我也意识到我可以在一个模板中创build与数据的二进制HTML表格,并更改文件标题,将其定义为一个Excel文件…用户下载并打开文件在Excel中,永远不知道区别。

我想知道的是 基于我有什么,如SQL和输出计划什么是最好的方式来最好的使用symfony做到这一点?

注意:Symfony 1.4和Doctrine。

我认为CSV也是一个不错的select,可以用Excel打开CSV文件。

无论如何,你可以做的是在你的模块上创build一个新的动作。 我build议你把它添加到操作参数 (它将显示“新logging”button)。

在你的行动中,你只需要执行你的请求:

 $this->dbh = Doctrine_Manager::getInstance()->getConnection('doctrine'); $stmt = $this->dbh->prepare($query); $stmt->execute(); $stmt->fetchAll(); 

你可以像这样添加你需要的响应头文件:

 $this->getResponse()->setHttpHeader('Content-Type', 'application/poney/excel'); 

如果你想要,你可以绕过模板:

 return $this->renderText($html); 

如果您尝试使用CSV \ o /

Interesting Posts