Zend 2 CSV动作

时间:2013-05-15 16:02:51

标签: zend-framework zend-framework2

我创建了以下操作,该操作成功返回CSV。但它仍然返回响应中的布局。从我所读到的布局不应该返回。 aAnyone知道如何禁用它吗?

public function csvAction() {

    $content = 'test';
    $response = $this->getResponse();

    $response->getHeaders()
             ->addHeaderLine('Content-Type', 'text/csv')
             ->addHeaderLine('Content-Disposition', "attachment; filename=\"my_filen.csv\"")
             ->addHeaderLine('Accept-Ranges', 'bytes')
             ->addHeaderLine('Content-Length', strlen($content));

    $response->setContent($content);

    return $response;
}

1 个答案:

答案 0 :(得分:-1)

尝试在csvAction函数的开头添加这些:

$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
相关问题