我觉得我遵循了https://github.com/FriendsOfCake/cakephp-csvview的说明。
1.我将公共函数export()添加到我的控制器。
public function export() {
$this->response->download('export.csv');
$data = $this->EstimatedRevenueFromCourseFees->find('all')->toArray();
$_serialize='data';
$_header = ['Semester', 'Total # of courses in the course bank', 'Total # of courses with approved fees', '# of courses offered', '% with fees', '# of courses with $100 & under', '% of courses with fees $100 & under', ' Revenue from $100 & under',
'# of courses with $100 & over', '% of courses with fees $100 & over', 'Revenure from $100 & over', '% of courses with fees $100 & over', 'Revenue from $100 & over', 'Total Revenue from course fees'];
$this->set(compact('data','_serialize','_header'));
$this->viewBuilder()-className('CsvView.Csv');
return;
}
使用composer安装插件并添加到bootstrap.php:
Plugin::load('CsvView');
将此添加到routes.php:
Router::extensions('csv');
<?= $this->Html->link('export', ['controller'=>'estimatedRevenueFromCourseFees', 'action'=>'export', '_ext'=>'csv'], ['class'=> 'btn btn-success']) ?>
但是当我点击按钮时,我得到了
Error: Create EstimatedRevenueFromCourseFeesController::export.csv()
不确定我错过了什么。它似乎没有认识到导出函数保持添加.csv我认为路由器语句将调整。