Yii2 Yii:: $app $app where is this variable instantiated?

Source: Internet
Author: User
The most commonly used service locator is the application (application) object, which can be accessed by \yii:: $app

Reply content:

The most commonly used service locator is the application (application) object, which can be accessed by \yii:: $app

Look at the source code to know, if your application is a Web application, its index.php
(new yii\web\Application($config))->run();
The constructor of the application is called, and its inherited self- yii\base\Application constructed method 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);}

After the specific instantiation process, you can continue to view the source code in a sequential order. What questions can you leave a message, view the source code can help you quickly understand the initialization of yiiframework and the operation process

It's a magical 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.