routing / remapping / default_controller question - 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 / remapping / default_controller question (/showthread.php?tid=14135) |
routing / remapping / default_controller question - El Forum - 12-19-2008 [eluser]Mark75[/eluser] Hi, i use hmvc and have a routing/remapping question. I want to keep my global routes.php clean and let my module-controllers do all the logic using _remap. This is in my global routes.php Code: $route['default_controller'] = "page"; My page controller uses _remap to handle all incoming requests. That works fine if 1) the URI contains no data (because it is the default_controller) or 2) i add Code: $route[':any'] = "page"; Is it possible to route all requests to the default_controller without defining extra routes for my other controllers? Regards Mark routing / remapping / default_controller question - El Forum - 12-19-2008 [eluser]Phil Sturgeon[/eluser] My CMS has been using routes set for each module with its own routes.php which didnt seem like too much of a pain until I saw this post. Thinking about it, we only want requests with 1 url segment to go through to page controller right? I haven't tested this, but in theory the following should get all 2+ segment URL's working. Code: $route['([a-z_-]+)/(.*)'] = "$1/$2"; I will make some modifications and test an evil plan to get all 1 segments working if they exist. Watch this space :-) routing / remapping / default_controller question - El Forum - 12-19-2008 [eluser]Mark75[/eluser] Hi again, to clearify: i want urls like Code: www.example.com default routed to my page-controller and Code: www.example.com/blog Code: www.example.com/portfolio routed to their corresponding controllers, the same for any other controller i might add. short: route everything to the pages controller if no other controller with the "segment-1-name" exists. Mark routing / remapping / default_controller question - El Forum - 01-05-2009 [eluser]simshaun[/eluser] I think you'd be best off writing a "Router" controller with a _remap. Every request is passed to the Router, which determines if segment 1 is a controller or not. routing / remapping / default_controller question - El Forum - 01-21-2009 [eluser]melpuggi[/eluser] [quote author="pyromaniac" date="1229727600"] Code: $route['([a-z_-]+)/(.*)'] = "$1/$2"; oh thank you routing / remapping / default_controller question - El Forum - 01-21-2009 [eluser]Dyllon[/eluser] You can extend the CI Router application/libraries/My_Router.php Code: class MY_Router extends CI_Router { routing / remapping / default_controller question - El Forum - 01-22-2009 [eluser]Phil Sturgeon[/eluser] Yea I started doing it the same way as Dyllon after seeing this method used in another post. It's much harder getting it working properly with Matchbox though! |