YII2 配置文件


$params = require(__DIR__ . '/params.php'); $config = [ // 用来区分其他应用的唯一标识 ID 'id' => 'oa', // 应用的根目录 'basePath' => dirname(__DIR__), // 引导启动组件,在每个请求处理过程都实例化某个组件即便它不会被访问 'bootstrap' => ['log'], // 应用组件,请谨慎注册太多应用组件,应用组件就像全局变量,使用太多可能加大测试和维护的难度。 一般情况下可以在需要时再创建本地组件
    // 只会在第一次访问时实例化,如果处理请求过程没有访问的话就不实例化
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '12345kjkj',
        ],
        'cache' => [// 使用类名注册 "cache" 组件
            'class' => 'yiicachingFileCache',
        ],
        'user' => [
            'identityClass' => 'appmodelsUser',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yiiswiftmailerMailer',
            // 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' => 'yiilogFileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),// 数据库配置.
     // 美化URL 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], ], // 该属性为一个数组,指定可以全局访问的参数 'params' => $params, // 指定应用所包含的 模块 'modules' => [ 'admin' => [ 'class' => 'appmodulesadminModule', ], ], // 指定你可能想展示给终端用户的应用名称,可以不唯一 'name' => '', // 控制器部署,数组的键代表控制器 ID,数组的值代表对应的类名 'controllerMap' => [ // 用类名申明 "account" 控制器 // 'account' => 'appcontrollersSiteController', // 用配置数组申明 "article" 控制器 // 'article' => [ // 'class' => 'appcontrollersPostController', // 'enableCsrfValidation' => false, // ], ], // 默认控制器 // 'defaultRoute' => 'accounts', // 维护模式,同一个方法处理所有用户请求 // 'catchAll' => [ // 'offline/notice', // 'param1' => 'value1', // 'param2' => 'value2', // ], // 指定控制器类默认的命名空间,默认为 appcontrollers // 'controllerNamespace' => '', // 应用版本 // 'version' => '1.0', // 指定未配置的请求的响应 路由 规则 // 'defaultRoute' => 'offline', // 渲染 视图 默认使用的布局名字,false不使用布局 // 'layout' => false, // 可以配置该属性为一个目录或者路径 别名 // 查找布局文件的路径,@app/views/layouts // 'layoutPath' => '', // 临时文件如日志文件、缓存文件等保存路径 // 'runtimePath' => '', // 视图文件的根目录 // 'viewPath' => '', // Composer 管理的供应商路径 // 'vendorPath' => '', // 应用事件 // 'on beforeRequest' => function($event){ // echo("<h1>处理请求之前</h1>"); // }, // 'on afterRequest' => function($event){ // echo("<h1>处理请求之后</h1>"); // }, // 'on beforeAction' => function($event){ // echo("<h1>控制器动作运行之前</h1>"); // }, // 'on afterAction' => function($event){ // echo("<h1>控制器动作运行之后</h1>"); // }, ]; if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yiidebugModule', ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yiigiiModule', ]; } return $config;

  

原文地址:https://www.cnblogs.com/wyzs/p/5306291.html