Yii框架浅析

index.php 中启动框架的语句:

Yii::createWebApplication($config)->run();

其中 Yii 类是继承自 YiiBase 基类,并且未对基类作任何覆盖。

framework/YiiBase.php  line 98

public static function createWebApplication($config=null)
{
    return self::createApplication('CWebApplication',$config);
}

同上文件 :line 125

public static function createApplication($class,$config=null)
{
    return new $class($config);
}

最后运行时的代码是:

$obj = new CWebApplication($config);
$obj->run();

framework/web/CWebApplication.php 此类中并无 run()方法,找基类 CApplication

framework/web/CApplication.php  line 158

public function run()
{
    if($this->hasEventHandler('onBeginRequest'))
	$this->onBeginRequest(new CEvent($this));
    $this->processRequest();
    if($this->hasEventHandler('onEndRequest'))
        $this->onEndRequest(new CEvent($this));
}

略过 $config 可能的繁复不计,实际运行 $this->processRequest(); CApplication 类定义了抽象方法 processRequest,故他的子类必须实现这个方法。见 CWebApplication line 125

public function processRequest()
{
    if(is_array($this->catchAllRequest) && isset($this->catchAllRequest[0]))
    {
        $route=$this->catchAllRequest[0];
	foreach(array_splice($this->catchAllRequest,1) as $name=>$value) {
	    $_GET[$name]=$value;
	}
    } else {
	$route=$this->getUrlManager()->parseUrl($this->getRequest());
	$this->runController($route);
    }
}

你可能感兴趣的:(Yii框架浅析)