gpt4 book ai didi

在 Symfony Admin 中使用多个连接到 Excel 的 Mysql 查询

转载 作者:行者123 更新时间:2023-11-29 03:44:40 25 4
gpt4 key购买 nike

我创建了一个不错的注册前端应用程序,用于为事件注册新用户。

我现在正在寻找从管理员生成的后端创建所有与会者的 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

如您所见,几乎没有标准联接和外部联接。

我还意识到我可以在模板中创建包含数据的普通 HTML 表格并更改文件标题以将其定义为 Excel 文件...用户下载并在 Excel 中打开文件并且永远不知道其中的区别。

我想知道的是;根据我所拥有的,例如sql 和输出计划什么是充分利用 symfony 来做到这一点的最佳方式?

注意:带有 Doctrine 的 Symfony 1.4。

最佳答案

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

无论如何,您可以做的是在您的模块上创建一个新的操作。我建议你将它添加到 actions params (它将与“新记录”按钮一起显示)。

在您的操作中,您只需执行您的请求:

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

您可以像这样添加您需要的响应 header :

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

如果你愿意,你可以绕过模板:

return $this->renderText($html);

如果您尝试提供 CSV\o/

则很有用

关于在 Symfony Admin 中使用多个连接到 Excel 的 Mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7787985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com