ファイルをダウンロードするために次のコードを使用しました
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
私はそれを解決するためにそれをたくさんグーグルで調べましたが、何もうまくいきませんでした。