Welcome Guest, Not a member yet? Register   Sign In
controller/index/arg ==> controller/arg?

I go with the routing flow. the _remap function has to be added to every controller and with routing you can do
$route['(controller1|controller2)/(.+)'] = '$1/index/$2';
If you have good regular expression skills you can get a lot of routes crammed on one line.

[eluser]Colin Williams[/eluser]
The problem with that approach, xwero, is that it makes the other methods of the controller (as in, besides the index() method) completely unreachable. And it's not true that the block of code needed in _remap() needs to appear in every Controller. You could abstract it out if you'd like. Besides, why assume that all controllers need this type of mapping? It's probably only true for a few.

You are right. But in my defense the index method can be used as controller router where you are using the _remap function. The only difference is that using the index as a controller router you need to check which methods are in the controller and with the _remap method you need to check which of the segments are not a method.

When i wrote putting the _remap function to every controller i was looking with maintainability goggles. Routes affect multiple controllers and their methods based on one file where the _remap function is controller based so you need to make changes in multiple files.

This _remap() method should fix it for you:
function _remap($method)
    if(method_exists($this, $method))
        call_user_func_array(array(&$this, $method), array_slice($this->uri->segment_array(), 2));
        call_user_func_array(array(&$this, 'index'), array_slice($this->uri->segment_array(), 1));
If no method with the name (the 2:nd segment) is found, index is called with the parameters from the rest of the segments.

Theme © iAndrew 2016 - Forum software by © MyBB