一 程序入口
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/http://www.cnblogs.com/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following line when in production mode
// defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once($yii);
Yii::createWebApplication($config)->run();
require_once($yii) 語句包含了yii.php 文件,該文件是Yii bootstrap file,包含了 yiibase的基礎類,yii完全繼承了yiibase
<?php
/**
* Yii bootstrap file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id: yii.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system
* @since 1.0
*/
require(dirname(__FILE__).'/YiiBase.php');
/**
* Yii is a helper class serving common framework functionalities.
*
* It encapsulates {@link YiiBase} which provides the actual implementation.
* By writing your own Yii class, you can customize some functionalities of YiiBase.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: yii.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system
* @since 1.0
*/
class Yii extends YiiBase
{
}
在 YiiBase 類中 定義了一些 比如:
public static function createWebApplication($config=null) // 創建啟動
public static function import($alias,$forceInclude=false) // 類導入
public static function createComponent($config) // 創建組件
public static function setApplication($app) // 創建類的實例 yii::app()
二 自動加載機制
還有比較重要的yii自動加載機制,在yiibase的最後引用了php的標准庫函數 spl_autoload_register(array('YiiBase','autoload')) 調用框架中的autoload方法
/**
* Class autoload loader.
* This method is provided to be invoked within an __autoload() magic method.
* @param string $className class name
* @return boolean whether the class has been loaded successfully
*/
public static function autoload($className)
{
// use include so that the error PHP file may appear
if(isset(self::$classMap[$className]))
include(self::$classMap[$className]);
else if(isset(self::$_coreClasses[$className]))
include(YII_PATH.self::$_coreClasses[$className]);
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);
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;
}
查看本欄目