zoukankan      html  css  js  c++  java
  • Codeigniter夸应用调用model

    Thinkphp里面的model都是可以跨应用调用,ci本身没有实现这个方法。
    可是稍微修改下,比Thinkphp用起来更容易调用。
    找到Loader.php文件的地址/system/core/Loader.php
    找到后打开文件,找到这个类的初始化方法,大概在124行的位置开始。

    public function __construct()
        {
            $this->_ci_ob_level  = ob_get_level();
            $this->_ci_library_paths = array(APPPATH, BASEPATH);
            $this->_ci_helper_paths = array(APPPATH, BASEPATH);
            $this->_ci_model_paths = array(APPPATH);
            $this->_ci_view_paths = array(APPPATH.'views/'   => TRUE);
     
            log_message('debug', "Loader Class Initialized");
        }

    只需要修改几行代码就可以实现了。

    public function __construct()
    {
        $this->_ci_ob_level  = ob_get_level();
        $this->_ci_library_paths = array(APPPATH, BASEPATH);
        $this->_ci_helper_paths = array(APPPATH, BASEPATH);
     
        $paths = array('weixin/', 'application/');
        $paths = array_merge(array(APPPATH,), $paths);
        $paths = array_unique($paths);
        $this->_ci_model_paths = $paths;
     
        $this->_ci_view_paths = array(APPPATH.'views/'   => TRUE);
     
        log_message('debug', "Loader Class Initialized");
     
     
    }

    将几个应用的目录名写在$paths这个数组里面。
    最后$paths这个数组复制给_ci_model_paths这个成员变量就行了。
    ci在加载model的时候会循环这个数组下面的models文件,如果找到文件就会自动跳出
    这里稍微做了一下处理,以当前的调用文件的目录优先查找.

  • 相关阅读:
    团队-科学计算器-模块测试过程
    结对-贪吃蛇-最终程序
    课后作业-阅读任务-阅读提问-3
    结对-贪吃蛇游戏-测试过程
    《团队-科学计算器-团队一阶段互评》
    结对-贪吃蛇项目-结对项目总结
    团队-科学计算器-开发文档
    《团队-科学计算器-模块测试过程》
    《团队-科学计算器-模块开发过程》
    结对-贪吃蛇-最终程序
  • 原文地址:https://www.cnblogs.com/hubing/p/4047961.html
Copyright © 2011-2022 走看看