Routing before 404 - 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 before 404 (/showthread.php?tid=8978) |
Routing before 404 - El Forum - 06-07-2008 [eluser]Ben Knowles[/eluser] In my application I allow users to have their own URI such as /~username. The controller I have set up for the user page is /users/index/username so they can use this or /~username. I currently have /~(.+) routed to this controller but I would prefer not to use the ~ character. What I want to do is set up a route so any URI that hasn't been matched to a controller is routed to the user controller. The only solution I've found so far is to extend the CI_Router class. I extended this class and modified the _validate_request function to load a controller instead of the show_404 function. This seems to work well enough, but is there a better way of doing this without having to extend the router class? Thanks Routing before 404 - El Forum - 06-07-2008 [eluser]marcoss[/eluser] You can use the _remap() function inside your controller. Routing before 404 - El Forum - 06-08-2008 [eluser]Ben Knowles[/eluser] How would that work? I don't think it will know which controller to use. It needs to load a specific controller when a controller isn't found. e.g. Say I have these pages and a controller for each one: /home /register /login Then I register and make my username 'ben'. I could then go to /ben (or anything not matching the controllers above) and it will load the user controller. I can't see how this can be done using remap. Routing before 404 - El Forum - 06-08-2008 [eluser]Michael Wales[/eluser] What I usually do - and this depends on how many "predefined controllers" you have, is just use routes.php. Like I said, if you have a lot of "non-user" controllers, it can get a bit hectic. Code: $route['about'] = 'info/about'; Routing before 404 - El Forum - 06-08-2008 [eluser]Ben Knowles[/eluser] Sounds like a good solution. If I don't end up with too many controllers then I'll just add them all to routes.php Thanks for the help |