Any Help Appreciated (Rerouting/Remapping) :) - 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: Any Help Appreciated (Rerouting/Remapping) :) (/showthread.php?tid=53615) |
Any Help Appreciated (Rerouting/Remapping) :) - El Forum - 07-31-2012 [eluser]Clowerweb[/eluser] Hello all, Basically, here's what I'm looking to do: I'm working with URLs to determine a page (obviously), and have the URLs set up in the following way: Code: domain.com/page This currently checks the database to see if segment 1 exists in the database as a page slug, and loads the page if so. So far, so good. Note: I'm handling this in the index() method on the main controller and using the following route in routes.php: Code: $route['(:any)'] = "index"; Here's the problem though. I also have controllers that need to be handled, such as /admin. Obviously, it's checking the db for a page with a slug "admin", and not finding it (which it shouldn't). What I need it to do is this: Check db, if slug exists, load page from db; If slug does not exist in db, check if there's a controller for it and load that instead (using CI's default handling of controller/function in URI); Else load 404. I suspect that there's a way to do this using _remap(), but I don't really understand how it works or what I need to do to get it going. Thanks for any and all help and suggestions! Any Help Appreciated (Rerouting/Remapping) :) - El Forum - 07-31-2012 [eluser]Aken[/eluser] http://ellislab.com/forums/viewthread/220528/#1016136 Any Help Appreciated (Rerouting/Remapping) :) - El Forum - 07-31-2012 [eluser]Clowerweb[/eluser] Nevermind, got it (found it on Stackoverflow), but please let me know if I'm doing this the correct way, or if there's a better way. In routes.php: Code: $route['default_controller'] = "index"; I am not using _remap(), but I feel like maybe I should be? Regardless, it seems to be working how I need it to for now, at least int he most basic sense, but I'm not sure how easily it will scale. Any Help Appreciated (Rerouting/Remapping) :) - El Forum - 07-31-2012 [eluser]Lewis Cowles[/eluser] Hi there, It sounds like you have a square peg and a round hole. If for example you changed from using your index page to another method, it can take the parameters as url variables; Using these parameters to query the database seems like a simple solution to me, if your goal was to build those pages from the database. You do need to be careful to build a solid abstraction layer however, because otherwise unscrupulous individuals may find exploits to query alternative data from your systems database. Also an open-ended system like this can have lots of holes and flaws so really, I wouldn't advise it. Code: function dbpage($field,$constraint1,$constraint2) Btw these methods can be used for /admin or /anything really as the methods live inside the main controller, be careful though, there is not much more reason to having one of these than having another controller |