模型配置路径使用 uid 而不是点符号
¥Model config path uses uid instead of dot notation
在 Strapi 5 中,要检索配置值,你需要使用 config.get('plugin::upload.myconfigval')
或 config.get('api::myapi.myconfigval')
¥In Strapi 5, to retrieve config values you will need to use config.get('plugin::upload.myconfigval')
or config.get('api::myapi.myconfigval')
此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。
¥This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
🔌 此重大更改是否会影响插件? | 是 |
---|
🤖 此重大更改是否由 codemod 自动处理? | 部分 |
---|
重大更改描述
¥Breaking change description
在 Strapi v4 中
¥In Strapi v4
使用 .
符号将模型添加到配置中,如下所示:
¥Models are added to the configuration using .
notation as follows:
strapi.config.get('plugin.upload.somesetting');
if ( strapi.config.has('plugin.upload.somesetting') ) {
strapi.config.set('plugin.upload.somesetting', false);
}
在 Strapi 5 中
¥In Strapi 5
使用 ::
替换 .
符号将模型添加到配置中,如下所示:
¥Models are added to the configuration using ::
replacing .
notation as follows:
strapi.config.get('plugin::upload.somesetting');
if ( strapi.config.has('plugin::upload.somesetting') ) {
strapi.config.set('plugin::upload.somesetting', false);
}
迁移
¥Migration
本节重新组合了有关引入的重大更改的有用说明和程序。
¥This section regroups useful notes and procedures about the introduced breaking change.
注意
¥Notes
-
如果 API 具有配置,也应使用
strapi.config.get(’api::myapi.myconfigval’)
进行访问。¥If an API has a configuration, it should also be accessed using
strapi.config.get(’api::myapi.myconfigval’)
. -
'plugin' 命名空间暂时支持弃用警告。这意味着引用
plugin.upload.somesetting
将在服务器日志中发出警告,并改为检查plugin::upload.somesetting
。¥The 'plugin' namespace has temporary support with a deprecation warning. This means that referencing
plugin.upload.somesetting
will emit a warning in the server log and checkplugin::upload.somesetting
instead. -
已创建 codemod 来帮助重构用户代码中的字符串,用
plugin::
和api::
替换plugin.
或api.
。¥A codemod has been created to assist in refactoring the strings in user code, replacing
plugin.
orapi.
withplugin::
andapi::
.
手动程序
¥Manual procedure
在大多数情况下,codemod 会自动处理更改。
¥A codemod will automatically handle the change in most cases.
如果 codemod 无法自动处理更改,用户需要手动替换所有字符串以定位新的配置路径。
¥In cases were the codemod does not automatically handle the change, users will need to manually replace all their strings to target the new config paths.