CodeIgniter Forums
Routes problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Routes problem (/showthread.php?tid=28992)



Routes problem - El Forum - 03-27-2010

[eluser]haxxorized[/eluser]
Hey, I have a little problem...


Say, if I wanted to go to a link: for example:
www.example.com/link

that would trigger the index function of the 'link' controller,
but say if I wanted to trigger a different function with this link, let's say 'function2'

then I could go to the config file and add to the routes array:
$routes['link'] = 'link/function2';

So that's all OK,
but now I want some parameters to add to that function, and the parameters come from the link...
how do I do that?


Routes problem - El Forum - 03-27-2010

[eluser]Rob Gordijn[/eluser]
ok, a fast reply:

Code:
class Link {
  function function2($par1 = '', $par2 = ''){
    echo $par1.' - '.$par2;
  }
}

now call example.com/link/function2/foo/bar Wink


Routes problem - El Forum - 03-28-2010

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
You might actually have to add something to your route:

Code:
$routes[‘link/(:any)’] = ‘link/function2/$1’;

Keep in mind that'll kill all the default routing to methods, and you'll need to create routes for each other method.