> 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment