CodeIgniter Forums
A routing question - 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: A routing question (/showthread.php?tid=3147)



A routing question - El Forum - 09-12-2007

[eluser]phester[/eluser]
So here's a scenario: You have a photo gallery application. You would like to have the URIs setup such that users can access their galleries using their nickname (assume it is unique) directly using a link that looks like:
Code:
http://www.blah.com/NICKNAME/controller/method

The easiest way I can think of to do this (and the most obvious) is to set up a route for this in "application/config/routes.php"

However, this means that every time a user signs up, this route will have to be manually created - not a good idea of course.

Anyone have any ideas on how to achieve this?! THANKS!


A routing question - El Forum - 09-12-2007

[eluser]zdknudsen[/eluser]
You could keep a cached array of your users somewhere and run through that in your routes file Smile Or, you could have routes for your other controllers above a (.*) route that'll route everything else to your usergalleries.


A routing question - El Forum - 09-12-2007

[eluser]Michael Wales[/eluser]
You almost have it right phester.

Rather than create a route for each of your users - create a route for all of your controllers/methods that you know will exist. Then create a route for everything else - this route will catch anything that doesn't fit the predefined route definitions.

So, if our URL is: blah.com/mynickname

You would route it to: profile/user/mynickname

The user method would then use the nickname as a parameter and you would be able to pull down their profile (or whatever it was you wanted.