2
votes

I have a route in my route.php :

$route['admin/(:any)'] = 'ix/$1';

It routes URI such as localhost/somename/admin/home to localhost/somename/ix/home.php controller.

The problem is if the URI is like this : localhost/somename/admin/blog/updates (nonexistant function), rather than returning 404, it will just run the blog controller construct code.

How do I avoid this? One option is to add the routing to accept only necessary parameters, but is there any other way?

Thanks

1
I think you need to clear up the question. admin/blog/updates should load ix/blog/updates based on your route. This would be looking for a blog function in the ix controller, so I'm not sure where "blog controller construct code" means. - Mike S.

1 Answers

1
votes

You can add a remap function to route the controller internally:

http://ellislab.com/codeigniter/user_guide/general/controllers.html#remapping

public function _remap($method, $params = array())
{
    if (method_exists($this, $method))
    {
        return call_user_func_array(array($this, $method), $params);
    }
    show_404();
}