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 

 

转载于:https://www.cnblogs.com/bravehunter/p/5673962.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值