UNIX艺术

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

应用执行流程:

index.php
    |
require_once($yii)
    |
    |------------->yii.php
                    |
                  require(YiiBase.php)
                    |
                    |---------------->YiiBase.php
                                        |
                                      Define YII_XXX global variable
                                        |
                                      Define Class YiiBase
                                        |
                                      Autload Class YiiBase (自动加载类机制)
                                        |
                                      require interface.php
                                        |
                    |<------------------|
                    |
                   define null Class Yii
                    |
    |<--------------|
    |
createWebApplication($config)---------->|
                                        |
                                      YiiBase::createApplication('CWebApplication',$config)
                                        |
                                      Create Instance of CWebApplication
                                        |
                                        |--------->CWebApplication
                                                      |
                                                   CApplication($config)构造函数
                                                      |
                                                      |------>|
                                                           setBasePath
                                                              |
                                                           set path alias
                                                              | 
                                                           preinit() 空方法
                                                              | 
                                                           initSystemHandlers()
                                                              | 
                                                           configure($config) 将配置文件信息保存到Application
                                                              |
                                                           attachBehaviors()
                                                              | 
                                                           preloadComponents() --> 装载在configure($config)中配置需要preload的components
                                                              | 
                                                           init()                                                              | 
                                                      |<------|
                                                      |
                                        |<------------|
                                        |
    |<----------------------------------|
    |
app->run()
    |
    |---->CWebApplication::processRequest()
                      |
                      |----> CWebApplication::runController($route)
                                       |
                                       |---->createController($route)
                                                    |
                                                 如果$route是空,添加默认controller,对于CWebApplication的controller是"site"
                                                    |
                                                 Controller类是SiteController,require该类文件
                                                    |
                                                 如果该类是CController的子类,修改id[0]为大写,创建该类的实例
                                                    |
                                                    |---->CSiteController
                                                              |
                                                          extends from Controller 这是客户化控制器的基本类,存在于components下
                                                          定义了页面的通用布局
                                                              |
                                                          使用CController构造函数创建对象CSiteController,具体初始化数据见yii-1.png
                                                              |
                                                    |<--------|
                                                备份$this->_controller
                                                $this->_controller = $controller
                                                    |
                                                 调用控制器类的init()方法,默认为空
                                                    |
                                                 调用控制器类的run()方法,默认为CController的run()
                                                    |
                                                    |---->createAction()
                                                              |
                                                           if($actionID==='') $actionID设置为$this->default ("index")
                                                              |
                                                              |Yes
                                                              |----> return CInlineAction($this, $actionID)
                                                              |No              |
                                                           从Map创建           |
                                                              |      执行当前类CInlineAction的父类CAction的构造函数
                                                              |      设置_controller和$id
                                                              |                |
                                                              |<---------------|
                                                              |
                                                              |
                                                           这里得到一个CAction的实例
                                                              |
                                                           $this->getModule()作为parent,为空则使用Yii::ap
                                                              |
                                                           $parent->beforeControllerAction() ??
                                                              | 
                                                            $this->runActionWithFilters($action,$this->filters());
                                                              | 
                                                            $parent->afterControllerAction($this,$action);
                                                    |<--------|
                                                    |
                                                  恢复原来的$oldController
                                       |<-----------| 
                                       |
                       |<--------------|
                       |
                  End of processRequest()
                       |
    |<-----------------|
    |
End of app->run()
posted on 2013-02-17 10:53  jinhuawang76  阅读(247)  评论(0编辑  收藏  举报