入口文件位置:$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;