The following is a piece of code using __autoload() for your reference:
Copy code The code is as follows:
/**
* Automatically load related class library files
*/
function __autoload($classname){
if(substr($classname,-6)=="Action"){
include APP_PATH.'controllers/'.$classname.'.class.php';
}elseif(substr($classname, -5)=="Model"){
include APP_PATH.'models/'.$classname.'.class.php';
}elseif($classname== "Smarty"){
include SYSTEM_PATH.'smarty/Smarty.class.php';
}else{
include APP_PATH.'common/'.$classname.'.class.php';
}
}
?>
Another way to include the path:
Copy the code The code is as follows:
function __autoload($class_name) {
$path = str_replace('_', DIRECTORY_SEPARATOR, $class_name);
require_once $path.'.php';
}
?>
Description: Convert the underscore to the directory separator (DIRECTORY_SEPARATOR). This can effectively manage library files and solve cross-platform problems.
http://www.bkjia.com/PHPjc/326444.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326444.htmlTechArticleThe following is a piece of code using __autoload() for your reference: Copy the code as follows: ?php / *** Automatically load related class library files*/ function __autoload($classname){ if(su...