Home > PHP Framework > YII > body text

What is the entry file of yii framework

王林
Release: 2020-03-11 14:05:17
Original
2922 people have browsed it

What is the entry file of yii framework

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(&#39;YII_DEBUG&#39;) or define(&#39;YII_DEBUG&#39;, true);
defined(&#39;YII_ENV&#39;) or define(&#39;YII_ENV&#39;, &#39;dev&#39;);
 
require(__DIR__ . &#39;/../../vendor/autoload.php&#39;);
require(__DIR__ . &#39;/../../vendor/yiisoft/yii2/Yii.php&#39;);
require(__DIR__ . &#39;/../../common/config/bootstrap.php&#39;);
require(__DIR__ . &#39;/../config/bootstrap.php&#39;);
 
$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . &#39;/../../common/config/main.php&#39;),
    require(__DIR__ . &#39;/../../common/config/main-local.php&#39;),
    require(__DIR__ . &#39;/../config/main.php&#39;),
    require(__DIR__ . &#39;/../config/main-local.php&#39;)
);
 
$application = new yii\web\Application($config);
$application->run();
Copy after login

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!

Related labels:
yii
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template