自动加载完成类的加载

来源:互联网 发布:百家cms v2.7 编辑:程序博客网 时间:2024/05/22 12:17
通过自动加载完成 需要图片上传类的时候,加载图片上传类;需要验证码类的时候,加载验证码类;需要smarty的时候,加载smarty (注意:功能类 和 smarty,数据库连接类不再同一个目录)
<?php
//功能类在 function文件夹下
//smarty类在smarty文件下
//数据库连接类在db文件夹下
$fileFunction = new fileFunction();
$checkcodeFunction = new checkcodeFunction();
$smarty = new smarty();
$db = new db();
function __autoload($class_name){
//先判断当前是 功能类 或者是 数据库类 还是smarty类
if(strpos($class_name,'Function')){
require "function/".$class_name.".class.php";//文件上传为 fileFunction.class.php 验证码类为 checkcode.class.php
}else if($class_name=='db'){
require "db/db.class.php";
}else if($class_name=='smarty'){
require "smarty/smarty.class.php";
}}
原创粉丝点击