The understanding of Yii Framework Yiiapp ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.