大飞_dafei

导航

yii2 config

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',
        'allowedIPs' => ['*']
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['*']
    ];
}

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',
        ],
    ],

 

扩展: 这里配置 reids 后,使用 phpstorm 写代码的时候,redis是没有提示的,比如 Yii::$app->redis->set("hello","world");,这里的reids在phpstorm中是跟踪不到的,解决这个问题,在 \vendor\yiisoft\yii2\base\Application.php 中的上面注释中添加如下:

* @property \yii\redis\Connection $redis  

这样 phpstorm 就可以跟踪代码,并且 Yii::$app->redis->set("hello","world");  这个set 也会有提示;

 

 

 

5、session

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

 

第二篇地址:  yii2 config 02

 

posted on 2017-12-12 09:50  大飞_dafei  阅读(206)  评论(0编辑  收藏  举报