Codeigniter路由行为与控制器魔术方法__call

The segments in a URI normally follow this pattern in Codeigniter:

XYZ.com/Class/Method/param1/param2

This works as expected when the called method is defined in the controller, but nothing works if I supply the URI with some undefined method to invoke the __call magic method that takes care of any undefined method.

__call is only invoked if its called from within the controller itself, not when I call some undefined method from the URI

Any explanation?

Thanks

In CodeIgniter, there is _remap. So if you go to

XYZ.com/Class/UndefinedMethod/param1/param2

then _remap will be called (actually _remap will always be called, so we need to make sure that methods that do exist are called correctly).

function _remap($method, $params=array()){
    $funcs = get_class_methods($this);
    if(in_array($method, $funcs)){ // We are trying to go to a method in this class
        return call_user_func_array(array($this, $method), $params);
    }
    // else do something else
}

Look in the server (Apache?) log file. Undoubtedly you will see PHP errors which caused processing to abort. Unless you cover undefined functions by remapping them to an error page, random URLs will cause "nothing" to seem to happen.