![]() |
[RESOLVED] 'default_controller' vs 'controller in sub-directory' - 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: [RESOLVED] 'default_controller' vs 'controller in sub-directory' (/showthread.php?tid=64145) |
[RESOLVED] 'default_controller' vs 'controller in sub-directory' - cloud_live - 01-20-2016 Hi All, I have some question to ask. I have a controller inside a sub-directory. To be more specific. I have a controller name 'Main' (Main.php) in sub-directory 'Report' so the path to this controller will be 'controllers/Report/Main.php'. I can access to the controller by typing the url like 'mywebsite.com/Report/Main'. The page displays correctly. Now I want to config the 'default_controller' to point to this controller when visitor type 'mywebsite.com' or 'mywebsite.com/index.php'. I opened 'config/routes.php' and changed $route['default_controller'] to 'Report/Main/'. I saved and closed. I tried 'mywebsite.com/index.php'. The webpage show me '404' error. I tried to enter the url manually. The target page is displayed correctly. I thought the controller named 'Main' might be reserved word. So I changed 'Report/Main.php' to 'Report/MainPage.php' and I also changed the controller name inside the file. Then I changed $route['default_controller'] to 'Report/MainPage/'. Still '404' error. Any advice would be appreciated. Thank you so much in advance. Have a nice day everyone ![]() With Best Regards, Chatawat RE: 'default_controller' vs 'controller in sub-directory' - josepostiga - 01-20-2016 According to http://codeigniter.com/user_guide/general/routing.html, you can't use a directory/controller combination as the default route configuration. RE: 'default_controller' vs 'controller in sub-directory' - cloud_live - 01-20-2016 Oh ... my bad. what about $route ? what if I set 'default_controller' to 'Main' (It will be located at 'controllers/Main.php') then I'll set $route['Main'] = 'Report/Main' ? thank you so much for your reply ![]() RE: 'default_controller' vs 'controller in sub-directory' - cloud_live - 01-20-2016 (01-20-2016, 04:24 AM)josepostiga Wrote: According to http://codeigniter.com/user_guide/general/routing.html, you can't use a directory/controller combination as the default route configuration. Thank you so much for your answer. Now I got answer for myself. I put 'Main.php' as 'controller/Main.php' and set $route['default_controller'] = 'Main' then I set the redirect to the url I want. Now you may close this thread ![]() With Best Regards, Chatawat |