0
自動加載類有一個神奇的功能(__autoload),我想知道是否有一種方法來加載沒有類的文件。自動加載文件,當使用需要功能
事情是這樣的:
require ('example_file'); // Trigger __autoloadfiles function
function __autoloadfiles($filename)
{
$files = array(
ROOT . DS . 'library' . DS . $filename. '.php',
ROOT . DS . 'application' . DS . $filename . '.php',
ROOT . DS . 'application/otherfolder' . DS . $filename. '.php'
);
$file_exists = FALSE;
foreach($files as $file) {
if(file_exists($file)) {
require_once $file;
$file_exists = TRUE;
break;
}
}
if(!$file_exists)
die("File not found.");
}