Yii framework is a purely object-oriented framework. When this framework is running, that is, when an application is accessed, it needs to be created Many objects, these objects then call many related methods to complete a web request.
This Yii::app() is the first object created. This object calls related methods and then the subsequent work is completed.
Yii::app() is mainly responsible for some global functional modules. For example, Yii::app()->getUser() returns a CWebUser instance (used to express the verification information of the current user). Because CWebApplication inherits CComponent, Yii::app()->getUser() can also be written as Yii::app()->user (see the description of CComponent, which is the cornerstone of Yii).
Yii::app() is an instance of class CWebApplication, so all the properties and methods that can be used by this class (including inherited classes) can be used by this object (some methods are core methods of system operation and are not recommended to be called directly ). For example, there is a method getLayoutPath() in CWebApplication to obtain the layout path, then we can do this:
echo Yii::app()->getLayoutPath(); // Output D:wwwphpernote.comprotectedviewslayouts
In addition, CWebApplication and its parent class CApplication define many components that can be used for the system, such as db, user, session, authManager, request, etc., and there are many others that are not listed one by one.
We can use the above components through Yii::app(), for example:
echo Yii::app()->request->url; //You can get the relative url address of the current request (/index.php?r=user/login)
Description:
Yii::app()->request; will create a request class object
Yii::app()->request->url; will call the attribute information in the class request. This attribute does not exist, or call the magic method __get of the parent class to indirectly call the geturl() method
Yii::app()->user; will call the user authentication component (CWebUser), and some properties and methods of CWebUser can be used.