0

我正在尝试按照此解决方案将数据导出到 Excel,但是当我单击下载链接时,它只会显示“服务器错误。可能因维护而停机....等”

我必须从教程中更改的唯一内容是 Csv 助手的名称。本教程指定了“Csv.php”,但我不得不将其命名为“CsvHelper.php”。当我打印进入该视图的变量时,它会显示数组。但是,当我删除它并且只列出与上面链接帖子中显示的完全相同的代码时,我收到服务器错误

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

这些是我必须按照“教程”的指示添加到我的服务器的文件

//Helper
/App/View/Helper/CsvHelper.php

//Vendor
/App/Vendor/excel/PHPExcel.PHP
/App/Vendor/excel/PHPExcel/    //contains the rest of PHPExcel

//view
/App/View/Orders/download.ctp  //Tutorial specifies /App/View/Homes/download.ctp so I made sure to change the link accordingly in the view which actually "links" to this

正如我之前提到的,当我在 download.ctp 上打印数组时看到这个

Array ( [0] => Array ( [Order] => Array ( [id] => 1 [userid] => 2 [order_status] => completed [email] => test@gmail.com [total] => 8.00 ) ) 

我的数组结构与本教程的结构相匹配

$orders[0]['Order'];

我必须用 CakePHP 配置什么来下载文件吗?我不知道从这里去哪里。

4

1 回答 1

3

在 cake 2.x 中输出不同类型的内容现在很容易并且是“小菜一碟”:)

视图类可以轻松切换到您需要的任何输出(json、xml、csv、..)。在你的情况下,我会使用https://github.com/josegonzalez/CsvView

$this->viewClass = 'CsvView.Csv';

并按照插件自述文件中的说明导出数据。

于 2013-06-13T09:17:42.457 回答