Skip to main content

模型配置路径使用 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.

 Is this breaking change affecting plugins?Yes
 Is this breaking change automatically handled by a codemod?Partly
(see use-uid-for-config-namespace)

重大变更描述

🌐 Breaking change description

在 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 中

模型通过使用 :: 替换 . 的表示法添加到配置中,如下所示:

🌐 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’) 进行访问。
  • 'plugin' 命名空间目前有临时支持,但会有弃用警告。这意味着引用 plugin.upload.somesetting 会在服务器日志中发出警告,并改为检查 plugin::upload.somesetting
  • 已经创建了一个代码修改工具来帮助重构用户代码中的字符串,将 plugin.api. 替换为 plugin::api::

手动操作

🌐 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.