我的解决方案在/ application / core /我创建一个MY_Loader.php(大写MY_L)
我创建了一个带有原型函数“model”副本的类MY_Loader
我评论行“$模型= ucfirst($模型);”
/application/core/MY_Loader.php的代码:
类MY_Loader扩展了CI_Loader
{
/ *这是来自/system/core/Moader.php的类CI_Loader函数模型的副本* /
公共函数模型($ model,$ name ='',$ db_conn = FALSE)
{
if(empty($ model))
{
返回$ this;
}
elseif(is_array($ model))
{
foreach($ model为$ key => $ value)
{
is_int($ key)? $ this-> model($ value,'',$ db_conn):$ this-> model($ key,$ value,$ db_conn);
}
返回$ this;
}
$ path ='';
//模型是否在子文件夹中? 如果是这样,解析出文件名和路径。
if(($ last_slash = strrpos($ model,'/'))!== FALSE)
{
//路径在最后一个斜杠的前面
$ path = substr($ model,0,++ $ last_slash);
//和它后面的模型名称
$ model = substr($ model,$ last_slash);
}
if(empty($ name))
{
$ name = $ model;
}
if(in_array($ name,$ this - > _ ci_models,TRUE))
{
返回$ this;
}
$ CI =&get_instance();
if(isset($ CI - > $ name))
{
抛出新的RuntimeException('您正在加载的模型名称是已经被使用的资源的名称:'。$ name);
}
if($ db_conn!== FALSE &&!class_exists('CI_DB',FALSE))
{
如果($ db_conn === TRUE)
{
$ db_conn ='';
}
$ this-> database($ db_conn,FALSE,TRUE);
}
//注意:这个条件下的所有代码都只是:
//
// load_class('Model','core');
//
//然而,load_class()实例化类
//缓存它们以备后用,并防止
// MY_Model是一个抽象类,是
否则无论如何都是次优的。
if(!class_exists('CI_Model',FALSE))
{
$ app_path = APPPATH.'core'.DIRECTORY_SEPARATOR;
if(file_exists($ app_path.'Model.php'))
{
require_once($ app_path.'Model.php');
if(!class_exists('CI_Model',FALSE))
{
抛出新的RuntimeException($ app_path。“Model.php存在,但不声明类CI_Model”);
}
}
elseif(!class_exists('CI_Model',FALSE))
{
require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php');
}
$ class = config_item('subclass_prefix')。'Model';
if(file_exists($ app_path。$ class。'。php'))
{
require_once($ APP_PATH $类。 'PHP。');
if(!class_exists($ class,FALSE))
{
抛出新的RuntimeException($ app_path。$ class。“。php存在,但是不声明class”。
}
}
}
//〜$ model = ucfirst($ model); / *这是我评论的那一行* /
if(!class_exists($ model,FALSE))
{
foreach($ this - > _ ci_model_paths as $ mod_path)
{
if(!file_exists($ mod_path.'models /'.$ path。$ model。'。php'))
{
继续;
}
require_once($ mod_path.'models /'.$路径$模型。 'PHP。');
if(!class_exists($ model,FALSE))
{
抛出新的RuntimeException($ mod_path。“models /".$路径。$ model。”.php存在,但是不声明class“。$ model);
}
打破;
}
if(!class_exists($ model,FALSE))
{
抛出新的RuntimeException('无法找到你指定的模型:'。$ model);
}
}
elseif(!is_subclass_of($ model,'CI_Model'))
{
抛出新的RuntimeException(“Class”。$ model。“已经存在,不扩展CI_Model”);
}
$ this - > _ ci_models [] = $ name;
$ CI - > $ name = new $ model();
返回$ this;
}
}