Welcome Guest, Not a member yet? Register   Sign In
A routing question
#1

[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!
#2

[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.
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB