dsiuz86842 2013-03-31 14:17
浏览 27
已采纳

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?

  • 写回答

1条回答 默认 最新

  • douduan9391 2013-03-31 14:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入