yii框架的入口文件是 web 文件夹下的 index.php 文件。
index.php文件的内容如下:
<?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.phprequire(__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 其实还有另外一个入口,是 yii2 命令行的入口文件,即顶级目录下的 yii 文件。
(相关文章教程推荐:yii框架)
yii 文件的内容如下:
#!/usr/bin/env php<?phpdefined('yii_debug') or define('yii_debug', true);// fcgi doesn't have stdin and stdout defined by default// 定义 stdin 和 stdoutdefined('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);
与 index.php 文件最大的区别在于,它使用的是 yii\console\application 类,而 index.php 中使用的 yii\web\application。
这就是 yii2 的两个入口,如果是 advanced 的项目的话,入口会更多,但基本内容都是这两种形式之一。
更多编程相关内容,请关注编程教程栏目!
以上就是yii框架的入口文件在哪里的详细内容。