The entry file of the yii framework is index.php, which is located under the web directory.
The content of the entry file is as follows:
<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/../../vendor/autoload.php'); require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/../../common/config/bootstrap.php'); require(__DIR__ . '/../config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../../common/config/main.php'), require(__DIR__ . '/../../common/config/main-local.php'), require(__DIR__ . '/../config/main.php'), require(__DIR__ . '/../config/main-local.php') ); $application = new yii\web\Application($config); $application->run();
How to understand the entry file code:
The first two lines are two define statements::defined('YII_DEBUG') or define(' YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev');
Define the current running mode and environment. If YII_DEBUG is defined, it means that the current state is debugging, and some debugging information will be output while the application is running. When an exception is thrown, there will also be a detailed call stack display. By default, YII_DEBUG is false . But during the development process, it is best to define it as true as written above to facilitate finding and analyzing errors.
If YII_ENV is defined, it specifies the running environment of the current application. The code above shows that the application will run in the dev environment. By default, YII_ENV is prod representing the production environment.
These environments are just names. The specific meaning and environment content depend on the definition of the environment. dev prod are the two default environments after Yii installation, representing the development environment and the final product environment respectively. There is also a test environment, which represents the test environment.
Environment and mode have different functions. The environment mainly affects the configuration file in the code. The three environments of YII_ENV's dev prod test will make the value of YII_ENV_DEV YII_ENV_PRODYII_ENV_TEST be true respectively. In this way, in the application configuration, especially in the same configuration file, different configurations can be made for different environments.
Related tutorial recommendations: yii framework
The above is the detailed content of What is the entry file of yii framework. For more information, please follow other related articles on the PHP Chinese website!