How to load class files automatically!
Now with AutoLoad (code as follows:), is there any other way to load the class file automatically? In addition to include (Specific file path)
PHP Code
function __autoload ($className) {if (file_exists (' model/'. $className. Class.php ') {include_once (' model/'. $className. Class.php ');} if (file_exists (' controller/'. $className. Class.php ') {include_once (' controller/'. $className. Class.php ');} $prefix = $GLOBALS [' groupName ']== ' main '? ': '. /'; if (file_exists ($prefix. ' Core/'. $className. Class.php ') {include_once ($prefix. ' Core/'. $className. Class.php ');} if (file_exists ($prefix. ' core/smarty-3.1.6/'. $className. Class.php ') {include_once ($prefix. ' core/smarty-3.1.6/'. $className. Class.php ');} if (file_exists ($prefix. ' core/smarty-3.1.6/sysplugins/'. $className. php ') {include_once ($prefix. ' core/smarty-3.1.6/sysplugins/'. $className. php ');}}
------Solution--------------------
Do you think this is more troublesome?
This is because your class files are put in more places, and you should use if else if or switch...case. Statement.
If you're in trouble, you can use arrays to save all the paths, like.
PHP Code
$arr = Array (' classPath1 ', ' classPath2 ', ' classPath3 '), foreach ($arr as $v) { $new _path = $v. $className. PHP '; if (file_exists ($new _path)) { include_once ($new _path); break; }}