2013-03-31 76 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;並讓調度員處理髮送。