In Yii2, where is the variable Yii: $ app instantiated?

Source: Internet
Author: User
The most common service locator is an application object. You can use Yii: $ app to access the most common service locator is an application object. You can use \ Yii :: $ app access

Reply content:

The most common service locator is the application object, which can be accessed through \ Yii: $ app

You can see the source code. If your application is a web application, in index. php
(New yii \ web \ Application ($ config)-> run ();
Call the construction method of the Application, and it inherits fromYii \ base \ ApplicationThe constructor is

Public function _ construct ($ config = []) {Yii: $ app = $ this; $ this-> setInstance ($ this); $ this-> state = self:: STATE_BEGIN; $ this-> preInit ($ config); $ this-> registerErrorHandler ($ config); Component ::__ construct ($ config );}

In the subsequent instantiation process, you can view the source code in order. If you have any questions, please leave a message and check the source code to help you quickly understand the initialization and running process of yiiframework.

This is a magic variable!

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.