yii入口分析

入口文件位置:$mysiteRoot/frontend/index.php

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);/**定义调试方式**/
defined('YII_ENV') or define('YII_ENV', 'dev'); /**定义环境变量**/

require(__DIR__ . '/../vendor/autoload.php'); /**Composer自动加载类**/
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');/**引导程序**/

$config = require(__DIR__ . '/../config/web.php');/**配置文件**/

(new yii\web\Application($config))->run();/**开始程序**/

自动加载文件:$mysiteRoot/vendor/autoload.php

/**真实自动加载类所在文件**/
require_once __DIR__ . '/composer/autoload_real.php';
/**注册加载类**/
return ComposerAutoloaderInit254a4315d47579fbdf7033bbd4fd7b27::getLoader();

引导程序:$mysiteRoot/vendor/yiisoft/yii2/Yii.php

require(__DIR__ . '/BaseYii.php');

class Yii extends \yii\BaseYii
{
}
/**告诉PHP碰到没有定义的类就执行 Yii->autoload **/
spl_autoload_register(['Yii', 'autoload'], true, true);
/**组件别名定义文件**/
Yii::$classMap = require(__DIR__ . '/classes.php');
/**Yii2.0 依赖注入(DI)和依赖注入容器实例化**/
Yii::$container = new yii\di\Container();

配置文件:$mysiteRoot/config/web.php

/**配置文件**/
$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic', /**APP Id**/
    'basePath' => dirname(__DIR__), /**定义APP 根路径**/
    'bootstrap' => ['log'],
    'components' => [   /**定义需要用到的组件**/
        'request' => [ /** request组件  定义cookie加密key **/
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'cookie_validation',
        ],
        'cache' => [ /**定义缓存类型**/
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [  /**user组件,可以添加其他参数**/
            'identityClass' => 'app\models\User',
            'idParam' => '__user', /**session前缀**/
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [ /**错误处理**/
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [  /**定义日志组件**/
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),  /**数据库参数**/
        /*
        'urlManager' => [  /**定义URL组件**/
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        */
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值