• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[RESOLVED] 'default_controller' vs 'controller in sub-directory'

#1
Question 
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 Smile

With Best Regards,
Chatawat
Reply

#2
According to http://codeigniter.com/user_guide/general/routing.html, you can't use a directory/controller combination as the default route configuration.
Best regards,
José Postiga
Senior Backend Developer
Reply

#3
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 Smile
Reply

#4
(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 Smile

With Best Regards,
Chatawat
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.