In my codeigniter controller I have only index function with an optional argument. If argument exists I load a view, otherwise I load another one. I use this _remap function:
function _remap($method){
$param_offset = 2;
// Default to index
if ( ! method_exists($this, $method))
{
// We need one more param
$param_offset = 1;
$method = 'index';
}
// Since all we get is $method, load up everything else in the URI
$params = array_slice($this->uri->rsegment_array(), $param_offset);
// Call the determined method with all params
call_user_func_array(array($this, $method), $params);
}
The problem is that when I check the argument in the index function it has always value equals to 0 that is the value I set as default.