yii2高级模板添加新增模块

本文介绍了如何在系统初始化时修改environmentsindex.php文件来配置API的专用模块,包括设置可写目录、可执行文件及Cookie验证密钥,以及如何在命令行下重新执行根目录下的init文件进行配置更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

例, 增加一个 API 的专用模块,在系统初始化的时候 修改 environments\index.php 文件,如下:

return [
    'Development' => [
        'path' => 'dev',
        'setWritable' => [    // 设置可写目录
            'api/runtime',      
            'api/web/assets',
            'api/controllers',   //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'api/models',        //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'backend/controllers',  //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'backend/models',    //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'backend/runtime',
            'backend/web/assets',
            'frontend/controllers',   //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'frontend/models',       //当前目录设置为可写为 Gii 使用,所以生产环境不需要配置
            'frontend/runtime',
            'frontend/web/assets',
        ],
        'setExecutable' => [
            'yii',
            'tests/codeception/bin/yii',
        ],
        'setCookieValidationKey' => [
            'api/config/main-local.php',
            'backend/config/main-local.php',
            'frontend/config/main-local.php',
        ],
    ],
    'Production' => [
        'path' => 'prod',
        'setWritable' => [
            'api/runtime',
            'api/web/assets',
            'backend/runtime',
            'backend/web/assets',
            'frontend/runtime',
            'frontend/web/assets',
        ],
        'setExecutable' => [
            'yii',
        ],
        'setCookieValidationKey' => [
            'api/config/main-local.php',
            'backend/config/main-local.php',
            'frontend/config/main-local.php',
        ],
    ],
];


后期也可以增加,命令行情况下重新执行根目录下的 init  文件即可,注意不要重写了配置文件



转载于:https://my.oschina.net/zhenhua2340/blog/506628

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值