CodeIgniter Forums
Using Default Routes with an ID as the first segment. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using Default Routes with an ID as the first segment. (/showthread.php?tid=13061)



Using Default Routes with an ID as the first segment. - El Forum - 11-09-2008

[eluser]tonybianco[/eluser]
Hi there. I'm new to CI but not so much to MVC. I have done some stuff with Rails and a few other frameworks. However, I'm running into a wall trying to figure out the routing of urls.

I'm wanting to set up a default route so that when someone types up mydomain.com/45678 <--(as in an affiliate id) then it will route to the proper controller and action with the numbers as the the id of the affiliate.

I spent time digging around the documentation but I couldn't find a way to do that for me. I was thinking that if I did this that it would work:
Code:
$rout['(:num)'] = "affiliates/affiliate_lookup/$1";

But it doesn't work nor does it even feel right when I'm coding that. Any suggestions would be very helpful?


Using Default Routes with an ID as the first segment. - El Forum - 11-09-2008

[eluser]bastones[/eluser]
Not sure if that's a typo - see $rout in your code - should be $route. That should work, remember segment URLs are done by class/function/ID order. I've never URI routed before so you're gonna have to refer here.


Using Default Routes with an ID as the first segment. - El Forum - 11-09-2008

[eluser]tonybianco[/eluser]
LOL! OMG!! It was a typo. It worked just fine actually.