At the entrance of the program, index.php with a sentence of Yii::createwebapplication ($config)->run (); Started running the app.
So, first look at the Cwebapplication constructor, as follows:
Public function __construct ($config =null){Yii::setapplication ($this);Set BasePath at early as possible to avoid troubleif (is_string ($config))$config =require ($config);if (Isset ($config [' BasePath '])){$this->setbasepath ($config [' basepath ']);unset ($config [' basepath ']);}Else$this->setbasepath (' protected ');Yii::setpathofalias (' Application ', $this->getbasepath ());Yii::setpathofalias (' Webroot ', dirname ($_server[' script_filename '));Yii::setpathofalias (' ext ', $this->getbasepath (). Directory_separator. ' Extensions ');$this->preinit ();$this->initsystemhandlers ();$this->registercorecomponents ();$this->configure ($config);$this->attachbehaviors ($this->behaviors);$this->preloadcomponents ();$this->init ();}
Then look at the flow of the run () function:
Public Function Run (){if ($this->haseventhandler (' OnBeginRequest '))$this->onbeginrequest (New CEvent ($this));Register_shutdown_function (Array ($this, ' End '), 0,false);$this->processrequest ();if ($this->haseventhandler (' onendrequest '))$this->onendrequest (New CEvent ($this));}
Finally see how the framework handles the request:
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);}
So, in the framework of the configuration file, the specified preload component will be executed before processing the request and routing analysis, then through the preload mechanism, we can do a lot of things, such as: to dynamically load some routing, you can customize the components, prior toProcessRequest process, in its own component$this->geturlmanager ()Addrules ().
It is worth mentioning that the component in Yii is a singleton pattern, first of all to determine whether there is already exist, and then to instantiate the component, which makes the components called in various places continuity is very good.
From for notes (Wiz)
Analysis of cwebapplication running flow in the detailed study of YII framework