PHP_CodeIgniter _remap重新定义方法

 

如果controller定义了_remap方法, 在_remap中重新定义方法

class Test extends CI_Controller{

    public function index(){
        echo "hello world";
    }

    //index.php/Test/success/id/1aa
    public function _remap($method,$params){
        if($method=='success'){
            $method .= '2'; 
            return call_user_func_array(array($this, $method), $params);
        }else{
            $this->index();
        }
    }

    public function success2($id,$key){
        var_dump($id);
        var_dump($key);
    }
}

上例中存在_remap方法, 重新定义success方法, 实现调用success2方法,  

注意,不能直接访问方法success2,需要通过success来方法

手册上的说明

 

posted on 2017-07-19 19:10  Slege  阅读(126)  评论(0编辑  收藏  举报

导航