【发布时间】:2015-10-30 00:11:19
【问题描述】:
我确实测试了两个代码以将类自动加载到页面,但对我不起作用!
怎么了?
spl_autoload_extensions('.php, .class.php');
spl_autoload_register(function ($name){
if('inc/'."{$name}".'.class.php'){
require('inc/'."{$name}".'.class.php');
}
});
与:
class FW{
public static function autoload($class){
$class = strtolower($class);
$fpath = realpath(dirname(__FILE__)).'/inc/'."{$class}". '.class.php';
if(is_readable($fpath)){
require_once($fpath);
}
}
}
spl_autoload_register('FW::autoload');
【问题讨论】:
-
您是否遇到任何错误?
-
是的,致命错误:找不到类“数据库”..
-
您应该在问题中包含错误,而不是在 cmets 中。