This method is triggered when the PHP engine encounters a class that is not instantiated. of course, you need to use _ autoload () in your php code. Below is a section using _ autoload () for your reference:
The code is as follows:
/**
* Automatically load related 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 method for path inclusion:
The code is as follows:
Function _ autoload ($ class_name ){
$ Path = str_replace ('_', DIRECTORY_SEPARATOR, $ class_name );
Require_once $ path. '. php ';
}
?>
Note: the underline is converted to the directory separator (DIRECTORY_SEPARATOR). This can effectively manage library files and solve cross-platform problems.