0

ファイルをダウンロードするために次のコードを使用しました

    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 

私はそれを解決するためにそれをたくさんグーグルで調べましたが、何もうまくいきませんでした。

4

1 に答える 1

2

コントローラーでダウンロードメソッドを使用できます

リンクを参照http://book.cakephp.org/2.0/en/views/media-view.html

于 2013-06-11T06:45:23.533 に答える