CodeIgniter Forums
Route Question (default controller) - 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: Route Question (default controller) (/showthread.php?tid=21538)



Route Question (default controller) - El Forum - 08-12-2009

[eluser]mrmuggles[/eluser]
I tried something like this with the routes.php file :

$route['default_controller'] = "category";
$route['scaffolding_trigger'] = "";

I was expecting that CI would load the "category" controller each time an associated controller wasn't found. For example, if I have a controller named user.php in the controller directory and I call the URL http://www.site.com/user, I would like it to load the "user.php" controller... so far, no problem.

But if I go to any other URL, like http://www.site.com/userabc/ or http://www.site.com/test, I would like to load the "category" controller. Like the doc said, the "default_controller" isn't really a default controller but it's more like an "home page controller"... Anyway, is there an easy way to achieve something like that without having to specify each single controller in the "routes.php" file?

Thanks! Smile


Route Question (default controller) - El Forum - 08-12-2009

[eluser]Dan Horrigan[/eluser]
If you want to do it site wide, the easiest way would be to simply modify the 404 Error view to redirect to that controller.


Route Question (default controller) - El Forum - 08-12-2009

[eluser]mrmuggles[/eluser]
Yea that was my last resort.. But I'll have to "reredirect" to the 404 page if there is one. I thought maybe there could be an easier "cleanier" way Wink


Route Question (default controller) - El Forum - 08-12-2009

[eluser]eoinmcg[/eluser]
You can also do it by extending the Router class

Check here for more details: http://ellislab.com/forums/viewthread/107451/#541043


Route Question (default controller) - El Forum - 08-17-2009

[eluser]mrmuggles[/eluser]
I changed the "_validate_request" method.
I just changed the last line

show_404($segment[0])
for
$this->set_class($this->default_controller);
$this->set_method('index');

And then in my controller, I just call show_404("") when I want to display a 404 error.

So far so good...