CakePHP下载文件错误
所以我基本上是想下载一个文件 我有以下行动:CakePHP下载文件错误,cakephp,download,Cakephp,Download,所以我基本上是想下载一个文件 我有以下行动: public function getfile() { $this->autoRender = false; $accesskey = 'mrPQVeJF8VFXpSq'; $data = $this->File->find('first', array('conditions' => array('File.accesskey =' => $accesskey)));
public function getfile() {
$this->autoRender = false;
$accesskey = 'mrPQVeJF8VFXpSq';
$data = $this->File->find('first', array('conditions' => array('File.accesskey =' => $accesskey)));
$filepath = substr($data['File']['path'], 17);
$this->response->file($filepath, array('download' => true, 'name' => $data['File']['name']));
return $this->response;
}
这会抛出一个错误:(我猜是$this->response->file()的行)
致命错误:找不到类“文件”文件:
C:\wamp\www\project\lib\Cake\Network\CakeResponse.php行:1347
类
文件
是一个。因此,将其用作模型可能会给您带来麻烦。我建议你换一下。阅读更多关于保留蛋糕和php单词的信息。这可能是你犯错误的原因
该错误的另一个原因是您不在filecontroller中,并且正在尝试调用那里的Find
模型。为此,请阅读如何从其他控制器加载模型(查找ClassRegistry::init
或$this->loadModel()
)
我在这里只是猜测,因为您正在“猜测引起问题的行是$this->response->file()
”。如果您不准确地猜测和调试是哪一行给了您这个错误,您可能会得到更准确的响应