2013-03-31 78 views
4

在我的控制器动作Content-Type的设置,我有这样的:的CakePHP忽略了响应

$pdf = $this->Invoice->makePdf($invoice); 
$this->response->charset('UTF-8'); 
$this->response->body($pdf); 
$this->response->type(array('pdf' => 'application/x-pdf')); 
$this->response->disableCache(); 
$this->response->send(); 

但是,无论我做什么,总是CakePHP的发送数据作为text/html; charset=utf-8。我也试过

$this->response->header(array('Content-Type' => 'application/x-pdf')); 

但它仍然发送它为text/html。我如何强制使用上面的内容类型发送回复?

回答

8

$this->response->type(array('pdf' => 'application/x-pdf'));存储/替换api中提到的关联密钥的内容类型。使用$this->response->type('pdf');来设置类型。

编辑:也不要致电$this->response->send();只是返回响应对象return $this->response;并让调度员处理发送。