现在用的是autoload(代码如下:),还有别的方法能自动加载类文件吗?除了include(具体文件路径)function __autoload($className){
if(file_exists('model/'.$className.'.class.php')){
include_once('model/'.$className.'.class.php');
}
if(file_exists('Controller/'.$className.'.class.php')){
include_once('Controller/'.$className.'.class.php');
}$prefix=$GLOBALS['groupName']=='main'?'':'../';
if(file_exists($prefix.'core/'.$className.'.class.php')){
include_once($prefix.'core/'.$className.'.class.php');
}
if(file_exists($prefix.'core/Smarty-3.1.6/'.$className.'.class.php')){
include_once($prefix.'core/Smarty-3.1.6/'.$className.'.class.php');
}
if(file_exists($prefix.'core/Smarty-3.1.6/sysplugins/'.$className.'.php')){
include_once($prefix.'core/Smarty-3.1.6/sysplugins/'.$className.'.php');
}}
if(file_exists('model/'.$className.'.class.php')){
include_once('model/'.$className.'.class.php');
}
if(file_exists('Controller/'.$className.'.class.php')){
include_once('Controller/'.$className.'.class.php');
}$prefix=$GLOBALS['groupName']=='main'?'':'../';
if(file_exists($prefix.'core/'.$className.'.class.php')){
include_once($prefix.'core/'.$className.'.class.php');
}
if(file_exists($prefix.'core/Smarty-3.1.6/'.$className.'.class.php')){
include_once($prefix.'core/Smarty-3.1.6/'.$className.'.class.php');
}
if(file_exists($prefix.'core/Smarty-3.1.6/sysplugins/'.$className.'.php')){
include_once($prefix.'core/Smarty-3.1.6/sysplugins/'.$className.'.php');
}}
解决方案 »
- 请问如何用php实现表单提交后以邮件的形式把表单内容发到邮箱中
- 我想用帝国cms6.5做个这样的网站,不知帝国是否能达到要求,请大家帮我鉴定一下
- WEB IM 需要用到什么技术啊
- 请问paypal是不是更新了 我的程式在结帐后出现错误 在线等
- 采集阿里巴巴搜索企业联系方式
- myphp开源模板调用falsh
- 大家帮帮忙了,急急急!!!!!!分少不了大家的【求救】
- 难,求高手,站内信群发,用户数5000w,如何设计程序和数据库
- windows系统下PHP安装和配置ssh2扩展?
- 我网站上整合了一个discuz x3 ,通信成功了,但是无法同步登陆,求高手指点
- 各位大侠帮帮忙,急求答案!!!谢谢!!!!
- 求一个随机数的算法
其实是因为你类文件放的地方比较多,而且你上面应该是用if else if或switch...case。语句。
如果你嫌麻烦的话可以用个数组来保存所有的路径比如。
$arr = array('classPath1','classPath2','classPath3');
foreach($arr as $v){
$new_path = $v.$className.'.php';
if(file_exists($new_path)){
include_once($new_path);
break;
}
}
这样就比较方便点,
比如你这几句:
if(file_exists('model/'.$className.'.class.php')){
include_once('model/'.$className.'.class.php');
}
if(file_exists('Controller/'.$className.'.class.php')){
include_once('Controller/'.$className.'.class.php');
}
从$className应该就能看出是controller还是model,应该不需要一个一个目录找,
而且,至少可以加个else吧
可能你是需要很多个class,所以用IF就可以了,代码中的break不要。
或者file_exists也不要,@include_once(屏蔽错误信息)这样应该比较快。