![]() |
[Solved] Routing Question. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: [Solved] Routing Question. (/showthread.php?tid=63443) |
[Solved] Routing Question. - wolfgang1983 - 10-30-2015 I know this question problem has been asked quite a few times. With codeigniter 3.0 + versions you are not able to have sub folders for default controller in routes.php // Not allowed $route['default_controller'] = subfolder/'welcome'; // Allowed $route['default_controller'] = 'welcome'; Has any one come up with a Custom MY_Router.php that could over ride that? to allow to have sub folders in default_controller in routes on CI3 versions? I know people say it not the norm to have it like that but would be good if could have option like what HMVC does. RE: Routing Question. - ignitedcms - 10-31-2015 Only the default route has this restriction, as it is the main entry point. Why not leave the welcome controller but have a redirect to your subfolder and method you want to be the default route. That's what I am doing. RE: Routing Question. - Martin7483 - 10-31-2015 You will need to override the _set_default_controller() method in the router class. Create a MY_Router.php class in ./application/core and add this: PHP Code: class MY_Router extends CI_Router { RE: Routing Question. - wolfgang1983 - 10-31-2015 (10-31-2015, 01:37 AM)Martin7483 Wrote: You will need to override the _set_default_controller() method in the router class. That works great can it be done also for the // Working $route['404_override'] = 'not_found'; // Not Working $route['404_override'] = 'error/not_found'; RE: Routing Question. - wolfgang1983 - 10-31-2015 (10-31-2015, 12:54 AM)iamthwee Wrote: Only the default route has this restriction, as it is the main entry point. I like to have most of the controllers in sub folders inside the controllers folder keeps it nice and tidy and separated but that is my opinion. Every one has there own ideas. RE: Routing Question. - Martin7483 - 10-31-2015 I would not advise doing that as you would need to edit ./system/core/CodeIgniter.php file. And it is never a good idea to edit the core files. But if you do want to do that this should work: PHP Code: if( is_dir(APPPATH.'controllers/'.$error_class) ) { Place it after these lines, round line number 433-436: PHP Code: if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2) RE: Routing Question. - wolfgang1983 - 10-31-2015 (10-31-2015, 02:23 AM)Martin7483 Wrote: I would not advise doing that as you would need to edit ./system/core/CodeIgniter.php file. And it is never a good idea to edit the core files. Thanks for your help and advice |