zoukankan      html  css  js  c++  java
  • CI框架两个application共用同一套 model

        既然是要共用model文件,就要告诉系统去何处加载我们的模型文件。这个工作是在 Loader.php 这个类中完成的,所以就要修改默认的行为:
        
      /**
         * List of paths to load models from
         *
         * @var array
         * @access protected
         */
        protected $_ci_model_paths        = array();
    
    

    1
    /** 2 * Constructor 3 * 4 * Sets the path to the view files and gets the initial output buffering level 5 */ 6 public function __construct() 7 { 8 $this->_ci_ob_level = ob_get_level(); 9 $this->_ci_library_paths = array(APPPATH, BASEPATH); 10 $this->_ci_helper_paths = array(APPPATH, BASEPATH); 11 12 //$this->_ci_model_paths = array(APPPATH); //model的默认路径 13 14 $this->_ci_model_paths = array(FCPATH); //修改 _ci_model_paths 为公共的/目标路径即可! 15 16 $this->_ci_model_paths = array(APPPATH, FCPATH); //指定可以从 APPPATH 和 FCPATH 这两个目录下获取我们的模型文件! 17 18 19 $this->_ci_view_paths = array(APPPATH.'views/' => TRUE); 20 21 log_message('debug', "Loader Class Initialized"); 22 } 23 24 不建议直接修改源码,最好是对CI进行扩展!。 25 在application/core/创建一个 MY_Loader.php 26 但是要注意,因为是两个应用 前台和后台,所以在两个地方的 core 目录下都要有一份 MY_Loader.php 扩展! 27 <?php 28 defined('BASEPATH') OR exit('No direct script access allowed!'); 29 30 class MY_Loader extends CI_Loader { 31 public function __construct() { 32 parent::__construct(); 33 34 //指定可以从 APPPATH 和 FCPATH 这两个目录下获取我们的模型文件! 35 $this->_ci_model_paths = array(APPPATH, FCPATH);
                或者:
                $this->_ci_model_paths = array(COMMON_PATH);
    39     }

    与此类似的,要让网站支持多套 模板/皮肤 也要对该类进行扩展。对应的属性是:
    /**
         * List of paths to load views from
         *
         * @var array
         * @access protected
         */
        protected $_ci_view_paths        = array();
    
    
    
     参考:http://blog.csdn.net/snow_finland/article/details/48464559 
  • 相关阅读:
    学习Python中的集合
    ubuntu14.04下 安装matlabR2015b遇到的一些问题及其解决方法
    matlab的一些关于块分类的函数~~~
    20145207 《Java程序设计》第二周学习总结
    20145207 调查问卷
    20145207 《Java程序设计》第一周学习总结
    10、装饰者模式
    9、观察者模式
    8、迭代器模式
    7、适配器模式
  • 原文地址:https://www.cnblogs.com/bravehunter/p/5673962.html
Copyright © 2011-2022 走看看