PHP的Yii框架中YiiBase入口类的扩展写法示例(2)

public static function autoload($className, $classMapOnly = false){ // use include so that the error PHP file may appear if (isset(self::$classMap[$className])) { include(self::$classMap[$className]); } elseif (isset(self::$_coreClasses[$className])) { include(YII_PATH . self::$_coreClasses[$className]); } elseif ($classMapOnly) { return false; } else { // include class file relying on include_path if (strpos($className, '\\') === false) // class without namespace { if (self::$enableIncludePath === false) { foreach (self::$_includePaths as $path) { $classFile = $path . DIRECTORY_SEPARATOR . $className . '.php'; if (is_file($classFile)) { include($classFile); if (YII_DEBUG && basename(realpath($classFile)) !== $className . '.php') { throw new CException(Yii::t('yii', 'Class name "{class}" does not match class file "{file}".', array( '{class}' => $className, '{file}' => $classFile, ))); } break; } } } else { include($className . '.php'); } } else // class name with namespace in PHP 5.3 { $namespace = str_replace('\\', '.', ltrim($className, '\\')); if (($path = self::getPathOfAlias($namespace)) !== false) { include($path . '.php'); } else { return false; } }

return class_exists($className, false) || interface_exists($className, false);    }    return true;}
config文件中的 import 项里的类或路径在脚本启动中会被自动导入。用户应用里个别类需要引入的类可以在类定义前加入 Yii::import() 语句。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a1d9957a482cf4eb53824ce86c58baba.html