![]() |
Help creating a route for sub-folder holding controllers - 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: Help creating a route for sub-folder holding controllers (/showthread.php?tid=63207) |
Help creating a route for sub-folder holding controllers - jLinux - 10-07-2015 In my CI application, all of the administrative actions are in controllers within the /controllers/admin/ folder.... Quote:[root@server application]# tree controllers/ The question I had was how can I have it so when they go to application.com/admin/, it shows a resource in a specified controller? I tried adding the following to application/config/routes.php, but it didn't work: PHP Code: $route['admin'] = '/admin/home'; Obviously creating an Admin.php inside the application/controllers/ directory would work for the /admin/ index, but make all the controllers inside the application/controllers/admin/ inaccessible. Thanks! RE: Help creating a route for sub-folder holding controllers - ignitedcms - 10-07-2015 I think narf mentioned the default route has to be top level and there are no plans to change this. The way I get around this is to set the route to go to a controller at the top level. Then in that controller I do a redirect... E.g redirect("admin/home", "refresh"); Not sure if that is what you mean? RE: Help creating a route for sub-folder holding controllers - jLinux - 10-07-2015 (10-07-2015, 01:53 PM)iamthwee Wrote: I think narf mentioned the default route has to be top level and there are no plans to change this. You mean put an Admin.php controller in the /application/controllers/ directory, and put a redirect in the Admin::index resource? That would kill all the other controllers in the /application/controllers/admin/ directory RE: Help creating a route for sub-folder holding controllers - cartalot - 10-07-2015 which version of codeigniter are you using? if you are using codeigniter 2 then use this, it allows you to use subfolders in the controller https://degreesofzero.com/article/controllers-in-sub-sub-folders-in-codeigniter.html you just create the file, drop it in, and thats it, works perfectly. if its CI 3, or if above solution does not work for CI 2, try adding index to the route $route['admin'] = '/admin/home/index'; RE: Help creating a route for sub-folder holding controllers - jLinux - 10-07-2015 (10-07-2015, 04:56 PM)cartalot Wrote: which version of codeigniter are you using? if you are using codeigniter 2 then use this, it allows you to use subfolders in the controller Im using CI3 And $route['admin'] = '/admin/home/index'; seemed to work! Wow, I guess it was because I didn't specify the index resource, assumed it would go to it automatically... Guess thats what happens when I assume >.< Thanks! RE: Help creating a route for sub-folder holding controllers - cartalot - 10-08-2015 Quote:And $route['admin'] = '/admin/home/index'; seemed to work! Wow, I guess it was because I didn't specify the index resource, assumed it would go to it automatically... Guess thats what happens when I assume >.< glad it helped! yeah there seem to be cases with CI 3 where you need to have 'index' in the route, but i haven't dived into it to figure out which conditions it is -- if anyone knows? |