CodeIgniter Forums
Default controller in index.php & routes.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Default controller in index.php & routes.php (/showthread.php?tid=50030)



Default controller in index.php & routes.php - El Forum - 03-11-2012

[eluser]Unknown[/eluser]
I set the default controller/function in index.php. This feature really solve a lot of coding effort for my old sites.

It used to work and today it stop working. I kept getting 404 page not found.

After debugging, I notice that the name of default controller coded in routes.php, is pointing to an invalid controller name (I renamed that controller today).
I changed the default controller in routes.php to some valid controller name and my index.php works again.

Even though CI is using the default controller in index.php, somehow CI still check for the default controller in routes.php

2 points to note if you set default controller in index.php
1) The default controller in routes.php must be valid
2) Always set 3 variables in index.php. Initially I did not set $routing['directory'] and it does not work.
- $routing['directory']
- $routing['controller']
- $routing['function']

Just to share my experience because I benefited a lot from this forum.




Default controller in index.php & routes.php - El Forum - 03-11-2012

[eluser]Aken[/eluser]
Why are you adding default controller code to the index.php file? Just set the default_controller route and you're fine...


Default controller in index.php & routes.php - El Forum - 03-12-2012

[eluser]PhilTem[/eluser]
@Aken
Why shouldn't he set it in index.php? EE has a part where you can set it, so there's no need for routes in that case.

@uzoom
I get/got the same problem. Your post kinda solves my post, even though not it's not a official bug-fix.
Should give you fix a try today.


Default controller in index.php & routes.php - El Forum - 03-12-2012

[eluser]Aken[/eluser]
Yes you CAN set it in EE, but it says right above it "END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE". So obviously you want to be really sure of what you're doing.

Anyway, I'm asking because setting a default route in index.php is rare and typically completely unnecessary. Read the comments right above it, which explain why it is not common and the precautions you'll need to take. If all he's trying to do is set the homepage, it's totally unnecessary to edit index.php.