最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

yii框架的入口文件在哪里

来源:动视网 责编:小采 时间:2020-11-03 18:18:14
文档

yii框架的入口文件在哪里

yii框架的入口文件在哪里:yii框架的入口文件是 web 文件夹下的 index.php 文件。index.php文件的内容如下:<php // comment out the following two lines when deployed to production // 定义 debug 的标记 defined('YII_DEBUG&#
推荐度:
导读yii框架的入口文件在哪里:yii框架的入口文件是 web 文件夹下的 index.php 文件。index.php文件的内容如下:<php // comment out the following two lines when deployed to production // 定义 debug 的标记 defined('YII_DEBUG&#


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.php
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

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

// new 一个 yiiwebApplication 的实例,并执行它的 run 方法
// 用 $config 作为 yiiwebApplication 初始化的参数
(new yiiwebApplication($config))->run();

Yii2 其实还有另外一个入口,是 Yii2 命令行的入口文件,即顶级目录下的 yii 文件。

(相关文章教程推荐:yii框架)

yii 文件的内容如下:

#!/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 一个 yiiconsoleApplication 的实例,并执行它的 run 方法
// 用 $config 作为 yiiconsoleApplication 初始化的参数
$application = new yiiconsoleApplication($config);
$exitCode = $application->run();
// 退出
exit($exitCode);

与 index.php 文件最大的区别在于,它使用的是 yiiconsoleApplication 类,而 index.php 中使用的 yiiwebApplication。

这就是 Yii2 的两个入口,如果是 advanced 的项目的话,入口会更多,但基本内容都是这两种形式之一。

更多编程相关内容,请关注Gxlcms编程教程栏目!

文档

yii框架的入口文件在哪里

yii框架的入口文件在哪里:yii框架的入口文件是 web 文件夹下的 index.php 文件。index.php文件的内容如下:<php // comment out the following two lines when deployed to production // 定义 debug 的标记 defined('YII_DEBUG&#
推荐度:
标签: 文件 文档 入口
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top