Php 调用未定义的方法CakerResponse::file()

Php 调用未定义的方法CakerResponse::file(),php,cakephp,controller,Php,Cakephp,Controller,我想在请求完成后下载一个文件。我正在使用此方法 公共函数sendFile($id){ 但是我得到了一个错误,比如调用未定义的方法CakerResponse::file()。我应该包括任何类或CakerResponse还是已经包括了? 谢谢我认为您正在使用CakePHP版本不假设$this->response->file()方法。如果是这样,那么您需要使用下载文件 注意: 对于$this->response->file() $this->response->file(

我想在请求完成后下载一个文件。我正在使用此方法 公共函数sendFile($id){

但是我得到了一个错误,比如调用未定义的方法CakerResponse::file()。我应该包括任何类或CakerResponse还是已经包括了?
谢谢

我认为您正在使用CakePHP版本不假设
$this->response->file()
方法。如果是这样,那么您需要使用下载文件

注意:

对于
$this->response->file()

$this->response->file(
                      WWW_ROOT.'files/'. 'somename.ext', // FULL PATH to file
                      array('download' => true, 'name' => 'SomeName')
                  );

对于
CakeResponse::file()

您应该始终提及您正在使用的确切cakephp版本。
$this->response->file(
                      WWW_ROOT.'files/'. 'somename.ext', // FULL PATH to file
                      array('download' => true, 'name' => 'SomeName')
                  );