Help undestanding Routes? |
[eluser]gRoberts[/eluser]
hi all, I am having some problems trying to understand the routes situation. I know how I can resolve the issue, but I don't want to go changing CI code if it can be done with Routes. Basically, what I want to do is every time a controller is requested, I want to check if that controller name is actually a username within my database. If it is, then I want to route it to /user/view and either pass the username or I can use uri->segment to get it. If it isn't, then I want it to continue what it normally does, either show the controller requested or throw an error if it doesn't exist. Does anyone have any idea's? Thanks Gav
[eluser]Michael Wales[/eluser]
You have to approach it in the opposite way - you define all of your known controllers, then you define an open rule for all of your users. Check out the following code, which accomplishes something similar (although I am using it for a CMS type system). I've added some comments to better explain: Code: // Match /admin/pages/delete/about-me to the pages controller, delete method, about-me parameter This code could be optimized some I am sure - I'm not the biggest whiz on RegEx
[eluser]gRoberts[/eluser]
I thought that was the case. I was hoping it wasn't though as its now restricting CI from what it excels in. If my client doesn't like www.domain.com/user/view/username then i'll have to edit the code or go the way you suggested. Thanks
[eluser]Sarfaraz Momin[/eluser]
You can also check the _remap function in the controller to acheive something similar to what you require. I have a site where www.domain.com/username sortta URLs are working gr8. |
Welcome Guest, Not a member yet? Register Sign In |