Welcome Guest, Not a member yet? Register   Sign In
Route Question (default controller)
#1

[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
#2

[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.
#3

[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
#4

[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
#5

[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...




Theme © iAndrew 2016 - Forum software by © MyBB