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文件,如果找到文件就会自动跳出
    这里稍微做了一下处理,以当前的调用文件的目录优先查找.

  • 相关阅读:
    C#读写XML no
    ComboBox、ListBox绑定和获取数据 no
    win7 安装oracle 11g no
    2011没有惊天动地 no
    Oracle 删除重复数据只留一条 no
    Oracle 创建用户并分配权限 no
    Oracle 导出、导入某用户所有数据(包括表、视图、存储过程...) no
    谢谢,博客园这么快就审批通过了我的申请!
    Eclipse 中 JAVA AWT相关包不提示问题(解决)
    Eclipse java项目转Maven项目
  • 原文地址:https://www.cnblogs.com/hubing/p/4047961.html
Copyright © 2011-2022 走看看