Codeigniter Routes regex - using dashes in controller/method names

前端 未结 9 1266
小鲜肉
小鲜肉 2020-11-29 01:32

I\'m looking for a one line route to route dashed controller and method names to the actual underscored controller and method names.

For example the URL



        
9条回答
  •  时光说笑
    2020-11-29 01:36

    You can use this _remap() method to handle such behavior. Place this method in your controllers or create a core controller and place it in.

    public function _remap($method, $params = array()){
        if(method_exists($this, $method)){
            return call_user_func_array(array($this, $method), $params);
        }else{
            $method = str_replace("-", "_", $method);
            if(method_exists($this, $method)){
                return call_user_func_array(array($this, $method), $params);
            }
        }
        show_404();
    }
    

提交回复
热议问题