CakePHP忽略响应中的Content-Type设置

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 the data as text/html; charset=utf-8. I have also tried

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

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

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

Edit: Also don't call $this->response->send(); just return the response object return $this->response; and let the dispatcher handle the sending.