不推荐使用:不推荐使用__autoload(),请使用spl_autoload_register()

时间:2018-06-10 04:56:28

标签: codeigniter

function __autoload($class) {
    if (strpos($class, 'CI_') !== 0) {
        if (file_exists($file = APPPATH . 'core/' . $class . php)) {
            include $file;
        }
    }
}
  

不推荐使用:不推荐使用__autoload(),请使用spl_autoload_register()   和致命错误:无法在codeigniter中重新声明__autoload()错误

2 个答案:

答案 0 :(得分:0)

要添加spl_autoload_register(),只需将此代码替换为您的代码,尤其是在route.php中。

function my_autoloader($class) {
if (strpos($class, 'CI_') !== 0) {
    if (file_exists($file = APPPATH . 'core/' . $class . php)) {
        include $file;
    }
  }
}
spl_autoload_register('my_autoloader');

希望这会有所帮助。

答案 1 :(得分:0)

我希望这个对你有用,因为我正在使用它

function your_autoloader($class) {

if (strpos($class, 'CI_') !== 0) {

    if (file_exists($file = APPPATH . 'core/' . $class . '.php')) {

        include $file;

    }
  }
}
spl_autoload_register('your_autoloader');

如果这没有帮助您拨打我的电话