douchuang4181 2012-08-17 20:56
浏览 66
已采纳

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

  • 写回答

2条回答 默认 最新

  • dream12001 2012-08-17 21:00
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?