I have a subdirectory in my controllers folder - possibly to set default controller? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: I have a subdirectory in my controllers folder - possibly to set default controller? (/showthread.php?tid=62519) |
I have a subdirectory in my controllers folder - possibly to set default controller? - sneakyimp - 07-23-2015 I have created a subdirectory called 'admin' in my application/controllers directory. I've got some controllers in there yes sir: Code: application/controllers/admin/Dashboard.php I'm wondering if it's possible to define a default controller::method for that subdirectory in case the url does not specify anything beyond http://example.com/admin For example, how would I route requests for http://example.com/admin to application/controllers/admin/Dashboard.php? I really hope I don't have to resort to defining a default controller for every subdirectory in my controllers directory via extensive changes to config/routes.php. Can anyone tell me if this is possible? RE: I have a subdirectory in my controllers folder - possibly to set default controller? - Narf - 07-24-2015 default_controller applies to all directories. If you set it to 'Dashboard', then application/controllers/Dashboard.php will be the default for example.com/ and application/controllers/admin/Dashboard.php will be the default for example.com/admin/ RE: I have a subdirectory in my controllers folder - possibly to set default controller? - Dracula - 07-24-2015 (07-23-2015, 05:12 PM)sneakyimp Wrote: I have created a subdirectory called 'admin' in my application/controllers directory. I've got some controllers in there yes sir: You can do something like this: PHP Code: $route['admin'] = 'admin/dashboard'; RE: I have a subdirectory in my controllers folder - possibly to set default controller? - Narf - 07-24-2015 (07-24-2015, 06:28 AM)Dracula Wrote: You can do something like this: No, you can't do that with CI3 and it was a bug in versions 2.x that it was allowed. RE: I have a subdirectory in my controllers folder - possibly to set default controller? - Dracula - 07-24-2015 (07-24-2015, 06:38 AM)Narf Wrote:(07-24-2015, 06:28 AM)Dracula Wrote: You can do something like this: Then I apologize. RE: I have a subdirectory in my controllers folder - possibly to set default controller? - sneakyimp - 07-24-2015 Thanks, Narf! RE: I have a subdirectory in my controllers folder - possibly to set default controller? - sneakyimp - 10-28-2016 Hm. It would seem that a default controller in a subdirectory cannot have methods other than index? For example, I have a subdirectory with a default controller in it: PHP Code: // application/controllers/subdir/Welcome.php http://example.com/subdir http://example.com/subdir/foo http://example.com/subdir/bar However, I get 404/not found for both the foo and bar urls. I am forced to define other controller classes to get those urls served. Is this supposed to be the case? Is there no way to define a default controller in a subdirectory that handles *all* requests for that subdir? RE: I have a subdirectory in my controllers folder - possibly to set default controller? - wolfgang1983 - 10-28-2016 I would create A core/MY_Router.php for CI3 Link MY_Router.php And use this PHP Code: <?php Then you can use default controller like $route['default_controller'] = 'admin/dashboard'; |