PHP autoload 自动加载类
作者:
晓得为_ | 来源:发表于
2018-04-08 14:48 被阅读0次function appAutoload($classname) {
$LIB_PATHS = array(APP_PATH . "/library",APP_PATH . "/model");
$arr = explode("_", $classname);
$file = '';
for ($i = 0; $i < count($arr); $i++) {
if ($i === count($arr) - 1) {
$file .= (ucfirst($arr [$i]) . ".php");
} else {
$file .= (strtolower($arr [$i]) . "/");
}
}
foreach ($LIB_PATHS as $path) {
$fileTmp = $path . '/' . $file;
if (file_exists($fileTmp)) {
require_once $fileTmp;
break;
}
}
}
spl_autoload_register("appAutoload");
本文标题:PHP autoload 自动加载类
本文链接:https://www.haomeiwen.com/subject/lvtgkxtx.html
网友评论