yii2有两个版本,一般来说,常用的都是basic版,大多数项目都可以足够满足了,少部分会使用advance版本, 这两个版本的配置文件的目录有点区别,basic版的配置文件目录很好找。基本就是basic\config目录下的web.php,而advance版本就比较分散一点,因为会根据网站入口的不同,分别在不同的目录下,例如bankend\config,common\config,frontend\config,console\config,具体目录的作用,这就不多做说明了,略微看一下都明白的。说穿了,大体上各配置文件的调用,看web\index.php就都了解了。
相关配置说明,逐步补充
'id' => 'basic', // ID,一般用来表示项目
'basePath' => dirname(__DIR__), // 方便代码中识别路径
'controllerNamespace' => 'adminplat\controllers', // controller类的路径,特别是advance版本,如果你目录名改了,就需要这个配置。
'defaultRoute' => 'home/index', // 默认路由,用来替换site类
'bootstrap' => ['log'],
'aliases' => [ // 照搬就行,基本也就是几个插件需要这个设定
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '', // 必填项,可以随意填写字母数字
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [ // 网站用户设定授权模式
'identityClass' => 'app\models\User', //指定用户校验类
'enableAutoLogin' => true, // 启用自动登录
'loginUrl' => ['home/login'], // 如果用户是访客,没有获得access授权,系统默认调用这个登录函数,框架自带默认值site/login
],
'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' => $db,
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,