Home > PHP Framework > YII > body text

Where is the entry file of the yii framework?

王林
Release: 2020-02-17 16:10:36
Original
4404 people have browsed it

Where is the entry file of the yii framework?

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(&#39;YII_DEBUG&#39;) or define(&#39;YII_DEBUG&#39;, true);
// 定义环境,有 &#39;dev&#39; 和 &#39;prod&#39; 两种
defined(&#39;YII_ENV&#39;) or define(&#39;YII_ENV&#39;, &#39;dev&#39;);

// 引入 vendor 中的 autoload.php 文件,会基于 composer 的机制自动加载类
require(__DIR__ . &#39;/../vendor/autoload.php&#39;);
// 引入 Yii 框架的文件 Yii.php
require(__DIR__ . &#39;/../vendor/yiisoft/yii2/Yii.php&#39;);

// 引入 web 的 config 文件,并将返回值即配置项放入 $config 变量中
$config = require(__DIR__ . &#39;/../config/web.php&#39;);

// new 一个 yii\web\Application 的实例,并执行它的 run 方法
// 用 $config 作为 yii\web\Application 初始化的参数
(new yii\web\Application($config))->run();
Copy after login

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(&#39;YII_DEBUG&#39;) or define(&#39;YII_DEBUG&#39;, true);

// fcgi doesn&#39;t have STDIN and STDOUT defined by default
// 定义 STDIN 和 STDOUT
defined(&#39;STDIN&#39;) or define(&#39;STDIN&#39;, fopen(&#39;php://stdin&#39;, &#39;r&#39;));
defined(&#39;STDOUT&#39;) or define(&#39;STDOUT&#39;, fopen(&#39;php://stdout&#39;, &#39;w&#39;));

require(__DIR__ . &#39;/vendor/autoload.php&#39;);
require(__DIR__ . &#39;/vendor/yiisoft/yii2/Yii.php&#39;);

// 引入 console 的 config 文件,并将返回值即配置项放入 $config 变量中
$config = require(__DIR__ . &#39;/config/console.php&#39;);

// new 一个 yii\console\Application 的实例,并执行它的 run 方法
// 用 $config 作为 yii\console\Application 初始化的参数
$application = new yii\console\Application($config);
$exitCode = $application->run();
// 退出
exit($exitCode);
Copy after login

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!

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