![]() |
Routing Question (:any) - 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: Routing Question (:any) (/showthread.php?tid=53905) |
Routing Question (:any) - El Forum - 08-13-2012 [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"; Routing Question (:any) - El Forum - 08-13-2012 [eluser]InsiteFX[/eluser] Make sure that it is the very last route in the file. Routing Question (:any) - El Forum - 08-16-2012 [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... Routing Question (:any) - El Forum - 08-16-2012 [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'; Routing Question (:any) - El Forum - 08-16-2012 [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/remapping-function-calls-in-codeigniter/ Hope it helps. |