Hi I did what was suggested in the above post and now this is my download function:
function download ($slug = null) { $this->view = 'Media'; $params = array( 'id' => 'example.zip, 'name' => 'example', 'download' => true, 'extension' => 'zip', 'path' => APP . 'gamefiles' . DS); $this->set($params); } I have three more links on whose click 3 different files should be downloded using this very download function, how should I make use of this slug to download different files. Should it be this: ??? function download ($slug = null) { $this->view = 'Media'; $params = array( 'id' => $slug, 'name' => 'example', 'download' => true, 'extension' => 'zip', 'path' => APP . 'gamefiles' . DS); $this->set($params); } On Feb 1, 7:13 pm, cricket <zijn.digi...@gmail.com> wrote: > On Tue, Feb 1, 2011 at 9:57 PM, newguy <aimanparv...@gmail.com> wrote: > > Hi > > I want to download four different files through 4 different links, I > > am using Media View to download file but I have to hardcode the file > > name in the download function in controller: > > > function download () { > > $this->view = 'Media'; > > $params = array( > > 'id' => 'example.zip', > > 'name' => 'example', > > 'download' => true, > > 'extension' => 'zip', > > 'path' => APP . 'files' . DS > > ); > > $this->set($params); > > } > > > This works fine for one file, now for link number 2,3,4 do I need to > > create 3 different actions and give different file names in them or is > > there a way in which I can use download() only and depending on which > > link has been clicked respective file is downloaded. > > Just pass the file name or slug in the link. I use the latter, where > each downloadable file has a title and slug: > > Router::connect( > '/downloads/:slug', > array( > 'controller' => 'files', > 'action' => 'download' > ), > array( > 'slug' => '[-0-9a-z]+', > 'pass' => array('slug') > ) > ); > > public function download($slug = null) { ... } > > Or you could pass the record ID: > > Router::connect( > '/downloads/:id', > array( > 'controller' => 'files', > 'action' => 'download' > ), > array( > 'id' => '[0-9]+', > 'pass' => array('id') > ) > ); > > public function download($id = null) { ... } -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php