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!