Codeigniter 2:误解了控制器中的with_remap方法

时间:2013-03-27 14:07:59

标签: php controller codeigniter-2 before-filter remap

public function _remap($method)
{
    if ($method == 'some_method')
    {
        $this->$method();
    }
    else
    {
        $this->default_method();
    }
}

这是我从官方网站上读到的。据我所知,_remap方法在所有操作之前被调用。但是这条指令$this->$method();意味着调用$ method会再次调用_remap,它就像循环一样。不是吗?

1 个答案:

答案 0 :(得分:1)

不,在初始化期间,框架会调用_remap,但是当您直接调用某个方法时,只执行函数内容...

希望它有用!

一些解释发现here

Important:  If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.