我使用以下代码下载文件
public function sendFile($filePath,$filename) {
$this->response->file($filePath, array('download' => true, 'name' => $filename));
return $this->response;
}
function download($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for upload', true));
$this->redirect(array('action' => 'index'));
}
$upload = $this->Upload->findById($id);
if (!$upload) {
$this->Session->setFlash(__('Invalid id for upload', true));
$this->redirect(array('action' => 'index'));
}
$filename = $upload['Upload']['filename'];
$filePath = APP.'uploads'.DS.$id.DS;
$this->sendFile($filePath,$filename);
}
但我收到以下通知和错误
Notice (8): Undefined property: UploadsController::$response
Fatal error: Call to a member function file() on a non-object
我用谷歌搜索了很多来解决它,但没有任何效果。