大飞_dafei

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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   大飞_dafei  阅读(207)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示