uri routing question |
[eluser]megabyte[/eluser]
I would like to find a way to have 1 controller named "friends". then be able to do this: www.mydomain.com/bob www.mydomain.com/mark www.mydomain.com/phil www.mydomain.com/tim But people will be signing up so I can't just do this by hard coding it in the routes.php file. The only other solution I could think of is to have a script that creates another controller each time a new person is added and it extends the base class. Is there some way I could use a hook to access the datatbase before the routes file is accessed and then have it read a dynamic list of routes or something like that? I just don't want to use: www.mydomain.com/friends/tim as it defeats the whole design of what I am trying to create.
[eluser]Michael Wales[/eluser]
Yes, it can be done with routing. URI routing is completed from top-down, so setup the routes for all of your hard-coded stuff (user/login, user/register, etc). Then setup a route for :any and direct it to whatever controller/method you want - something like friends/view would work. Use uri->segment(1) to determine if it's someone's username and process. BTW: Remember not to let people register with the username of your controllers - otherwise they'll never be able to see their profiles.
[eluser]megabyte[/eluser]
I figured it out. but it doesn't seem to work when you want to call a function. www.mydomain.com/bob works but if I have a function called age() in the controller and I go to www.mydomain.com/bob/age All I get is it calling the index() and i set up a route to in an attempt to fix it with $route[':any/age'] = "test/age"; but that did not help either. Any ideas? K I wish we could delete our posts when we solve them ourselves, lol. I figured out its all about the order in which you list the routes, which is what you were talking about earlier.
|
Welcome Guest, Not a member yet? Register Sign In |