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