I am trying to download my uploaded files(image) by id from the database(phpmyadmin).
but there’s an error said that variable $id is undefined.
this is the code i’m using, i got this code from some tutorial website.
public function download()
{
$berkas = new BerkasModel();
$data = $berkas->find($id);
return $this->response->download('uploads/berkas/' . $data->berkas, null);
}
how can i fix this so i can download the uploaded files?
2
Answers
You need to pass the variable
$id
to the function.Specific implementation depends on your setup. Looking at the small code fragment you posted (and the absence of any request variable extraction), pass it as function parameter:
public function download($id)
.Furthermore you need to adapt your
routes.php
and the calling<a>
to reflect this change:routes.php
:<a href>
:You need
$id
in functiondownload()