文件
🌐 Documents
在 Strapi 5 中,文档是一个仅限 API 的概念。文档代表了给定内容类型条目所有不同的内容变体。
🌐 A document in Strapi 5 is an API-only concept. A document represents all the different variations of content for a given entry of a content-type.
单一类型包含一个唯一文档,而集合类型可以包含多个文档。
🌐 A single type contains a unique document, and a collection type can contain several documents.
当你使用管理员面板时,从未提到文档的概念,并且对终端用户并不必要。 用户在内容管理器中创建和编辑条目。例如,作为用户,你要么列出给定语言环境下的条目,要么编辑给定语言环境中特定条目的草稿版本。
🌐 When you use the admin panel, the concept of a document is never mentioned and not necessary for the end user. Users create and edit entries in the Content Manager. For instance, as a user, you either list the entries for a given locale, or edit the draft version of a specific entry in a given locale.
但是,在 API 级别,条目字段的值实际上可以具有:
🌐 However, at the API level, the value of the fields of an entry can actually have:
- 英语和法语语言环境的内容不同,
- 甚至在每个语言环境中为草稿和已发布版本设置不同的内容。
包含所有语言环境的所有草稿和已发布版本内容的存储桶是一个文档。
🌐 The bucket that includes the content of all the draft and published versions for all the locales is a document.
使用 文档服务 API 操作文档将帮助你创建、检索、更新和删除文档或其中包含的特定数据子集。
🌐 Manipulating documents with the Document Service API will help you create, retrieve, update, and delete documents or a specific subset of the data they contain.
下列图表显示了内容的所有可能变体,这取决于内容类型启用了哪些功能,例如国际化 (i18n)和草稿与发布:
🌐 The following diagrams represent all the possible variations of content depending on which features, such as Internationalization (i18n) and Draft & Publish, are enabled for a content-type:
- Neither i18n nor Draft & Publish enabled
- Only Draft & Publish enabled
- Only i18n enabled
- i18n + Draft & Publish enabled
- 如果内容类型启用了国际化 (i18n) 功能,则一个文档可以拥有多个文档语言环境。
- 如果在内容类型上启用了“草稿与发布”功能,文档可以同时拥有已发布版本和草稿版本。
要与文档或它们所代表的数据进行交互:
🌐 To interact with documents or the data they represent:
- 从后端 服务器(例如,从控制器、服务以及插件的后端部分)使用 文档服务 API。
- 从应用的前端部分,使用 REST API 或 GraphQL API 查询你的数据。
有关 API 的更多信息,请参阅 内容 API 介绍。
🌐 For additional information about the APIs, please refer to the Content API introduction.
后端和前端 API 之间的一个重要区别是关于未传递参数时返回的默认版本:
🌐 An important difference between the back-end and front-end APIs is about the default version returned when no parameter is passed:
- 文档服务 API 默认返回草稿版本,
- 而 REST 和 GraphQL API 默认返回已发布的版本。