CakePHP ignores Content-Type setting in response

In my controller action, I have this:

$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(); 

However, no matter what I do, CakePHP always sends data as text/html; charset=utf-8 text/html; charset=utf-8 . I also tried

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

But he still sent it as text/html . How can I get the response to be sent using the above content type?

+4
source share
1 answer

Doing $this->response->type(array('pdf' => 'application/x-pdf')); saves / replaces the content type for the associated key, as specified in the api . Use $this->response->type('pdf'); to set the type.

Edit: Also do not call $this->response->send(); , just return the response object return $this->response; and let the dispatcher handle the dispatch.

+8
source

All Articles