我正在使用此功能查看数据库中的pdf文件:
public function pdfPreview($taskId){
$file = $this->StoredFile->find('first', array(
'conditions' => array(
'StoredFile.id' => $taskId
),
'contain' => false
));
$this->response->body($file['StoredFile']['data']);
$this->response->type('pdf');
//$this->response->header('Content-Disposition', 'inline');
//Return response object to prevent controller from trying to render a view
return $this->response;
}
有没有办法在没有渲染布局的情况下使用CakeResponse为布局设置标题,因为我试图将文件名设置为标题,但我没有找到解决方案?
答案 0 :(得分:0)
通常$title_for_layout
视图var会传递给html并放在<title>
标记之间。
但是,据我所知,您正在使用来自de database的原始数据输出PDF。然后,浏览器会将其解释为呈现PDF视图。浏览器认为它正在显示文件,因此当您在Content-Disposition
标题中设置文件名时,它将在其标题中显示该文件。就像他们在https://stackoverflow.com/a/2016016/1535656