yii2 config

来源:互联网 发布:2016中日贸易数据 编辑:程序博客网 时间:2024/06/04 19:25

1、语言设置

return [    'aliases' => [        '@bower' => '@vendor/bower-asset',        '@npm'   => '@vendor/npm-asset',    ],    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',    'components' => [        'cache' => [            'class' => 'yii\caching\FileCache',        ],    ],    'language' => 'zh-CN',//这里是重点   common/config/main.php];

2、yii2底部debug

if (!YII_ENV_TEST) {       //backend/config/main-local.php   这里是右下角debug和gii    // configuration adjustments for 'dev' environment    $config['bootstrap'][] = 'debug';    $config['modules']['debug'] = [        'class' => 'yii\debug\Module',    ];    $config['bootstrap'][] = 'gii';    $config['modules']['gii'] = [        'class' => 'yii\gii\Module',    ];}


3、配置URL规则

        'urlManager' => [            'enablePrettyUrl' => true,            'rules' => [                'home' => 'test/index',                '<alias:about>' => 'test/page',                'page/<alias>' => 'test/page',            ]        ],

4、缓存(memcache、redis、fileCache等缓存)

    'components' => [        'cache' => [            'class' => 'yii\caching\MemCache',    //memcached            'servers' => [                [                    'host' => 'server1',                    'port' => 11211,                    'weight' => 100,                ],                [                    'host' => 'server2',                    'port' => 11211,                    'weight' => 50,                ],            ],        ],    ],
----------------------------------------------------
    'components' => [        'redis' => [            'class' => 'yii\redis\Connection',            'hostname' => '127.0.0.1',            'port' => 6379,            'database' => 0,            'password'=>'password'        ],        'cache' => [            'class' => 'yii\redis\Cache', //redis            'keyPrefix' => 'redis_01_key',        ],    ],

5、session

        'session' => [            'class' => 'yii\redis\Session',            'keyPrefix' => 'session_key',        ],