Routing Question (:any) |
[eluser]CI-Newb[/eluser]
Hello CI Forum & Coders! I would like the following url to display a users profile: Code: http://www.website.com/username-here The following is what I am trying to use to acomplish this. Code: $route['(:any)'] = "profile/view/$1";
[eluser]InsiteFX[/eluser]
Make sure that it is the very last route in the file.
[eluser]Oscar Dias[/eluser]
That's a question that I have as well. I think the problem with using your solution, besides having to write all routes manually, is that you can't have a user with the username with the same value as your controllers. If you have a controller '/login', you have to prevent users creating the username 'login', otherwise no one will be able to access that user's profile. The same will happen for all your controllers. I usually end up doing: Code: $route['user/(:any)'] = "profile/view/$1"; Or something like it...
[eluser]CroNiX[/eluser]
You can also use a negative rule and exclude controllers. But yeah, once you set up a route, you need to set up routes for all controllers basically, or exclude them from routing like below. Otherwise catch-all routes using (:any) or (.*) will catch everything, including additional segments. Code: $route['((?!login|logout).*)'] = 'profile/view/$1';
[eluser]jotorres1[/eluser]
There is a simpler way of doing this. By using the _remap function within codeigniter, you can override the: domain/class/method way of getting to a specific method you want. I wrote about it, so you should take a look. http://www.jotorres.com/2011/12/remappin...deigniter/ Hope it helps. |
Welcome Guest, Not a member yet? Register Sign In |