既然是要共用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