The entry file of the yii framework is the index.php file in the web folder. The content of the
index.php file is as follows:
<?php // comment out the following two lines when deployed to production // 定义 debug 的标记 defined('YII_DEBUG') or define('YII_DEBUG', true); // 定义环境,有 'dev' 和 'prod' 两种 defined('YII_ENV') or define('YII_ENV', 'dev'); // 引入 vendor 中的 autoload.php 文件,会基于 composer 的机制自动加载类 require(__DIR__ . '/../vendor/autoload.php'); // 引入 Yii 框架的文件 Yii.php require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); // 引入 web 的 config 文件,并将返回值即配置项放入 $config 变量中 $config = require(__DIR__ . '/../config/web.php'); // new 一个 yii\web\Application 的实例,并执行它的 run 方法 // 用 $config 作为 yii\web\Application 初始化的参数 (new yii\web\Application($config))->run();
Yii2 In fact, there is another entrance, which is the entry file of the Yii2 command line, that is, the yii file in the top-level directory.
(Related article tutorials recommended: yii framework)
The content of the yii file is as follows:
#!/usr/bin/env php <?php defined('YII_DEBUG') or define('YII_DEBUG', true); // fcgi doesn't have STDIN and STDOUT defined by default // 定义 STDIN 和 STDOUT defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); // 引入 console 的 config 文件,并将返回值即配置项放入 $config 变量中 $config = require(__DIR__ . '/config/console.php'); // new 一个 yii\console\Application 的实例,并执行它的 run 方法 // 用 $config 作为 yii\console\Application 初始化的参数 $application = new yii\console\Application($config); $exitCode = $application->run(); // 退出 exit($exitCode);
The biggest difference from the index.php file is that, It uses the yii\console\Application class, and the yii\web\Application used in index.php.
These are the two entrances to Yii2. If it is an advanced project, there will be more entrances, but the basic content is one of these two forms.
For more programming related content, please pay attention to the Programming Tutorial column on the php Chinese website!
The above is the detailed content of Where is the entry file of the yii framework?. For more information, please follow other related articles on the PHP Chinese website!