Use s 0 en to automatically load the implementation code of the undefined class using s 1 en of

  • 2020-05-30 19:41:57
  • OfStack

Following is a section of code using s 1en () for your reference:

*  Automatically loads related class library files 
function __autoload($classname){
include APP_PATH.'controllers/'.$classname.'.class.php';
}elseif(substr($classname, -5)=="Model"){
include APP_PATH.'models/'.$classname.'.class.php';
include SYSTEM_PATH.'smarty/Smarty.class.php';
include APP_PATH.'common/'.$classname.'.class.php';

Another way to include paths:

function __autoload($class_name) {
$path = str_replace('_', DIRECTORY_SEPARATOR, $class_name);
require_once $path.'.php';

Note: convert the underscore to a directory delimiter (DIRECTORY_SEPARATOR), which effectively manages library files and solves cross-platform problems.

Related articles: