2 回答
TA贡献1854条经验 获得超8个赞
在文档之前,您可以使用该框架,查看如何将字符串作为文件发送
public function export()
{
$this->autoRender = false;
$id = $this->request->getQuery('id');
$invoice = $this->Invoices->get($id, ['contain' => ['Customers', 'ItemInvoices' => ['ItemProformas' => ['ItemDeliveryNotes' => ['ItemOrders' => ['Orders' => ['Customers']]]]]]]);
$fpr = new ExportInvoice();
$fpr->SetInvoice($invoice);
// header('Content-type: text/xml');
// header('Content-Disposition: attachment; filename="' . $fpr->getFilename() . '"');
$xml = $fpr->asXML();
$response = $this->response;
$response = $response->withStringBody($xml);
// use $response->body($xml); for versions before 3.4.0
$response = $response->withType('xml');
$response = $response->withDownload($fpr->getFilename());
return $response;
}
TA贡献1911条经验 获得超7个赞
只需使用die()或exit()
public function export()
{
$this->autoRender = false;
$id = $this->request->getQuery('id');
$invoice = $this->Invoices->get($id, ['contain' => ['Customers', 'ItemInvoices' => ['ItemProformas' => ['ItemDeliveryNotes' => ['ItemOrders' => ['Orders' => ['Customers']]]]]]]);
$fpr = new ExportInvoice();
$fpr->SetInvoice($invoice);
if (!headers_sent())
{
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="' . $fpr->getFilename() . '"');
}
else
{
//Do something else to let them know they can't expect a file
die();
}
die($fpr->asXML());
}
- 2 回答
- 0 关注
- 118 浏览
添加回答
举报