In continuation of the previous post:
In my site on page display there are 4 links and user clicks on it to
download 4 different files. This is the cpt file for this:

<p>Select the game to download</p>
<ul>
<li><?php echo $html->link('Game 1',array('action'=>'download')); ?></
li>
<li><?php echo $html->link('Game 2',array('action'=>'download1')); ?></
li>
<li><?php echo $html->link('Game 3',array('controller' =>
'users','action' => 'download','slug' => Inflector::slug('game'))); ?
></li>
<li>Game 4</li>
</ul>

This is my Router::connect:
        Router::connect('/users/
display/:slug',array('controller'=>'users','action'=>'download'),array('slug'=>'[-0-9a-
z]+','pass'=>array('slug')));
This file to be downloaded on clicking link three is game.zip

Please help me get this link working , thanks

On Feb 3, 11:50 pm, newguy <[email protected]> wrote:
> 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 <[email protected]> wrote:
>
>
>
>
>
>
>
> > On Tue, Feb 1, 2011 at 9:57 PM, newguy <[email protected]> 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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to