Table of Contents
Understanding of Yii framework Yiiapp()
Articles you may be interested in
Home Backend Development PHP Tutorial Understanding Yii framework Yiiapp()_PHP tutorial

Understanding Yii framework Yiiapp()_PHP tutorial

Jul 13, 2016 am 09:57 AM
yii

Understanding of Yii framework Yiiapp()

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.

Articles you may be interested in

  • Text box effect that displays line numbers, compatible with IE, Firefox and other browsers
  • Detailed analysis of the directory structure of the yii framework
  • php creates a simple case of your own MVC framework, providing ideas for reference only
  • Improving user experience must start from analyzing the user’s visual senses
  • select into from prompt Undeclared variable ..... Solutions to errors
  • Yii controller action parameter binding processing
  • What is the php design pattern and how to understand it
  • php Output Control In-depth understanding of ob_flush The difference between flush

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/981486.htmlTechArticleUnderstanding of Yii framework Yiiapp() Yii framework is a purely object-oriented framework. When this framework is running, That is, when an application is accessed, many objects need to be created, which are...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Yii3 framework in php? How to use Yii3 framework in php? May 31, 2023 pm 10:42 PM

How to use Yii3 framework in php?

How to use PHP framework Yii to develop a highly available cloud backup system How to use PHP framework Yii to develop a highly available cloud backup system Jun 27, 2023 am 09:04 AM

How to use PHP framework Yii to develop a highly available cloud backup system

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Jun 19, 2023 am 08:09 AM

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications?

Symfony vs Yii2: Which framework is better for developing large-scale web applications? Symfony vs Yii2: Which framework is better for developing large-scale web applications? Jun 19, 2023 am 10:57 AM

Symfony vs Yii2: Which framework is better for developing large-scale web applications?

Data query in Yii framework: access data efficiently Data query in Yii framework: access data efficiently Jun 21, 2023 am 11:22 AM

Data query in Yii framework: access data efficiently

How to convert yii objects into arrays or directly output to json format How to convert yii objects into arrays or directly output to json format Jan 08, 2021 am 10:13 AM

How to convert yii objects into arrays or directly output to json format

Yii2 Programming Guide: How to run Cron service Yii2 Programming Guide: How to run Cron service Sep 01, 2023 pm 11:21 PM

Yii2 Programming Guide: How to run Cron service

Form builder in Yii framework: building complex forms Form builder in Yii framework: building complex forms Jun 21, 2023 am 10:09 AM

Form builder in Yii framework: building complex forms

See all articles