在我的codeigniter控制器中,我只有一个带可选参数的索引函数。如果argument存在,就加载一个视图,否则就加载另一个。我使用这个_remap函数:
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);
}
问题是,当我检查索引函数中的参数时,它的值总是等于0,这是我设置为默认值
_remap()
函数的原始签名:
function _remap($method, $params = array());
看$params
数组而不是使用URI
库,你很好去