![]() |
Custom URL handling (just a little) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Custom URL handling (just a little) (/showthread.php?tid=7110) Pages:
1
2
|
Custom URL handling (just a little) - El Forum - 03-25-2008 [eluser]Jupiter[/eluser] I'd like to parse URLs before CI dows routing. Purpose is take the first level (the controller) out of the URL and use the segments as a tree-like structure to display contents of my database. Example: www.mysite.com/shoes/sneakers/nike should display all rows from my db where category = 'shoes', type = 'sneakers' and brand = 'nike'. I cannot setup controllers for every category (because they keep adding up) and I don't want to generally disable the URL-handling. Actually I just want to check, if there is a category matching the first segment and handle it (and in case there isn't - continue with CI URLs as usual). Any hint where to begin? Peter Custom URL handling (just a little) - El Forum - 03-25-2008 [eluser]GSV Sleeper Service[/eluser] just use the URL segments say for example you have a default controller called Store Code: class Store extends Controller { [edit] see here for more details - http://ellislab.com/codeigniter/user-guide/libraries/uri.html Custom URL handling (just a little) - El Forum - 03-25-2008 [eluser]xwero[/eluser] The GSV Sleeper Service is for one controller only and it has to be the default controller. If your application matches those requirements it's the solution for you. If one of the requirements is not met i think you are better of using routing instead of trying to create a custom routing. Custom URL handling (just a little) - El Forum - 03-25-2008 [eluser]louis w[/eluser] I would create a custom loader.php file (My_Loader.php in app libraries). Currently it kicks to a 404 page at the end if no controller is found. Instead check if there is a uri set and send it to a specified controller. Then use the uri->segments thing to pull out the data. Custom URL handling (just a little) - El Forum - 03-25-2008 [eluser]Jupiter[/eluser] Thanks a lot for the quick replies! I think, what louis wrote is actually what I was looking for but a custom function in routing.php might also do it. When I have found a solution, I'll post it here! Peter Custom URL handling (just a little) - El Forum - 03-29-2008 [eluser]Jupiter[/eluser] Now here's what I did: In routes.php I added Code: // CUSTOM ROUTES: That's not beautiful, but it works. Any ideas? Peter Custom URL handling (just a little) - El Forum - 03-29-2008 [eluser]louis w[/eluser] You should DEF not be doing that mysql_connect there. You realize that CI has an entire database library to centralize everything? Pass this off to a controller and let it do all the work. Not to mention loading and parsing all the brands every single page request is not a good idea performance wise. Custom URL handling (just a little) - El Forum - 03-29-2008 [eluser]Jupiter[/eluser] Louis, when processing routes.php , CI has not yet connected to the database, so I have to do it manually - or is there any way to load the db libraries before routing takes place? Where can I put my custom routes so that it will be skipped, when a contoller or another routing fits the URL? Peter Custom URL handling (just a little) - El Forum - 03-29-2008 [eluser]louis w[/eluser] Thats why I would be doing this in loader.php Right before it currently sends to a 404 (at the end), query the db with just the brand in the uri (don't get all of them). If its valid then send to your controller. Custom URL handling (just a little) - El Forum - 03-29-2008 [eluser]Jupiter[/eluser] Are you refering to the Loader.php library? Where exactly does it send to 404? |