在OS X上的safari中下载csv文件时出现CakePHP问题

时间:2014-07-02 13:56:35

标签: cakephp csv cakephp-2.0 export-to-csv

以下是返回csv文件的控制器函数:

public function export(){

    if ($this->request->is('get')) {
        throw new MethodNotAllowedException();
    }

    $employee = $this->request->query['employee'];
    $from = $this->request->query['from'];
    $to = $this->request->query['to'];

    $events = $this->Event->export($employee, $from, $to);

    $this->response->download("export.csv");
    $this->set(compact('events'));
    $this->layout = 'ajax';
    return;

}

以下是我的称呼方式:

echo $this->Form->postLink(
    $this->Html->image('export.png', array('width'=>'200px', 'height'=>'79px')),
    array(
        'controller' => 'events',
        'action' => 'export',
        '?' => array(
            'employee'=>$_POST['data']['Event']['employee'],
            'from'=>$_POST['data']['Event']['from'],
            'to'=>$_POST['data']['Event']['to'],
            'ext'=>'csv'
        )
    ),
    array('escape'=>false)
);

除了OS X上的safari之外,它在所有平台和浏览器上都运行良好。我尝试在safari上下载它(仅在OS X上),该文件获得了.html扩展名。

非常感谢任何帮助或指导。

0 个答案:

没有答案