The YII framework is a purely object-oriented framework that, when run, when an application is accessed, needs to create many objects that invoke many related methods to complete a Web request.
This Yii::app () is the first object to be created, and this object calls the relevant method, and the subsequent work is done.
Yii::app () is primarily responsible for some of the global functional modules, such as Yii::app ()->getuser (), which returns the Cwebuser instance (which is used to express authentication information for the current user). Because Cwebapplication inherits Ccomponent, Yii::app ()->getuser () can also write Yii::app ()->user (see note on ccomponent, which is the cornerstone of Yii).
Yii::app () is an instance of the class cwebapplication, so that this class (including inherited classes) can be used by properties and methods, which can be used (some methods are the core method of system operation, not recommended for direct invocation). For example, in Cwebapplication there is a method Getlayoutpath () to get the layout path, then we can do this:
Echo Yii::app ()->getlayoutpath (); Output D:\www\phpernote.com\protected\views\layouts
In addition, Cwebapplication and its parent class capplication define a lot of available components for the system, DB, User, session, AuthManager, request, and others.
We can use the above components through Yii::app (), for example:
Echo Yii::app ()->request->url; Can get the relative URL address of the current request (/index.php?r=user/login)
Description
Yii::app ()->request; The request class object is created
Yii::app ()->request->url; Call the property information inside the class request, this property does not, or call the parent class's Magic method __get indirectly calls the Geturl () method
Yii::app ()->user; The user authentication component (Cwebuser) is called, and some properties and methods of the Cwebuser can be used.
The understanding of Yii Framework Yiiapp ()