CakePHP 3 - 缺少导出CSV控制器功能

时间:2018-02-12 22:21:12

标签: twitter-bootstrap-3 cakephp-3.0 export-to-csv

我觉得我遵循了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;
    }
  1. 使用composer安装插件并添加到bootstrap.php:

    Plugin::load('CsvView');

  2. 将此添加到routes.php:

    Router::extensions('csv');

    1. 将此添加到我的视图文件中:
    2. <?= $this->Html->link('export', ['controller'=>'estimatedRevenueFromCourseFees', 'action'=>'export', '_ext'=>'csv'], ['class'=> 'btn btn-success']) ?>

      但是当我点击按钮时,我得到了

      Error: Create EstimatedRevenueFromCourseFeesController::export.csv()
      

      不确定我错过了什么。它似乎没有认识到导出函数保持添加.csv我认为路由器语句将调整。

0 个答案:

没有答案