类不自动加载?

时间:2012-11-18 19:59:57

标签: php spl-autoload-register

我的应用程序中有一个自动加载器功能:

 spl_autoload_register(function ($className) {
if (file_exists(ROOT . DS . 'library'  . DS . 'intranet'  . DS  . 'classes' . DS .strtolower($className) . '.php')){
    require_once(ROOT . DS . 'library'  . DS . 'intranet'  . DS  . 'classes' . DS .strtolower($className) . '.php');
    print_r($className." loaded <br/>");
} else if (file_exists(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'view' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'view' . DS . strtolower($className) . '.php');
} else {
    throw new Exception("Class: $className not autoloaded!");
}
});

在我的一个文件中,一个会话管理器,它调用一个名为database的类。之前没有调用database类,此时应该自动加载。

然而,它似乎不是 - 说,我正在打印出正在加载的类列表:

debug loaded 
sessionmanager loaded 
database loaded 
database loaded 

所以看起来它正在加载,对吗?

在sessionnmanager类中:

Fatal error: Class 'database' not found 

我的自动加载器看起来不错吗?

我在__construct方法的数据库类中放了一个打印,是的,确实已经被调用了。

0 个答案:

没有答案
相关问题