When building a website with AnQiCMS, we often need to retrieve detailed information of various documents through the API interface. Among them,archive/detailThe interface is the key to obtaining detailed information of a single document.Many developers and content operators may be curious about whether the data structure returned by this interface will be different for different types of documents, such as ordinary articles, news, or product information on e-commerce websites.The answer is: it has both unity and high flexibility.
Firstly, the security CMS is designedarchive/detailAt the interface, a set of core and unified data fields is provided for all document types. Whether you request an ordinary article or a specific product detail, you will find the returneddataObject sees such asid(Document ID),title(Title),seo_title(SEO title),description[Summary],url_token(URL alias),created_time(Creation time) andupdated_time(Updated time) and other basic information.These fields constitute the basic framework of the document, ensuring consistency in core attributes across different types of content, greatly facilitating the data processing and display logic for the front-end, allowing you to easily present the universal attributes of the document.
On this unified structure, the CMS also integrates some fields specifically designed for certain document types. A striking example isprice(price) andstockWhen you get a product document, these fields will appear directly.dataRoot level, providing you with the pricing and inventory status of the products.而对于普通文章这类不需要价格和库存属性的文档,这些字段则可能以默认值(如0)或不显示的方式呈现,这反映了系统对常见商业场景的直接支持,省去了在自定义字段中重复配置的麻烦。
However, the real strength of Anqi CMS lies in its flexible "model" mechanism, as well as its close association withextraField. Each document belongs to a specific "document model" (throughmodule_idLabel), and each model can be configured with a series of custom fields. It is these custom fields that are the key to the significant changes in the data structure of different document types. When you go througharchive/detailThe document details obtained through the interface will aggregate all custom fields configured for the model of the document into the returned data.extrathe object. For example, a technical article mayextracontainsauthor(Author)、version(Version) etc. custom fields, while a product document may containextrainmaterial(Material)、color(Color)、size(Size) and more detailed product parameters.extraThe structure of the field iskey => itemin the form of,keyis the calling name of the custom field,itemwhich includesname(Field Name)、value(The value entered) anddefault(The default value). This means, by means of theextraThe parsing of the field, you can completely present a rich and diverse content according to the needs of different document models, greatly expanding the form of content expression.
This design pattern brings great convenience and scalability.It avoids hardcoding all possible fields in the core interface, thus maintaining the simplicity and efficiency of the API.archive/detailWhen fetching data through the interface, it can bemodule_idused to judge the model of the current document (e.g.module_ida value of 1 usually represents an article,module_idauto 2 may represent a product), and flexibly handle and displayextraField custom data.This allows the AnQi CMS to easily handle a variety of content management scenarios from simple blog posts to complex e-commerce products, without the need to design a separate API interface for each content type.
In summary, the security CMS ofarchive/detailThe interface design takes into account both universality and specificity. It provides a set of stable basic data structures, while alsoprice/stocketc. specific fields and highly flexibleextraCustom field mechanism, which has realized the dynamic adaptation to different types of document data structures. This means that, when you are developing, you need to adapt according tomodule_idandextraThe content of the field, perform targeted data analysis and page rendering, thereby fully utilizing the powerful content management capabilities of Anqi CMS.
Common Questions (FAQ)
1. How to judge whether a document is an article or a product type?You can through the returned data in themodule_idField to determine the type of document. Anqi CMS assigns a uniquemodule_idFor example,module_idis usually for article models,module_idauto 2 may represent the product model. You canmodule/listget all module details through the interface, includingidandtitle, to establish the corresponding mapping relationship.
2. If I add the custom fields 'Color' and 'Size' to the product model, how will they be reflected in the interface return data?archive/detail接口的返回数据中如何体现?These custom fields will all be displayed.dataObjects'extraFor example, you may see a structure like this:
"extra": {
"color": {
"name": "颜色",
"value": "红色",
"default": ""
},
"size": {
"name": "尺寸",
"value": "XL",
"default": ""
}
}
You need to access their values based on the custom fields.field_name(i.e., here)colorandsize).
3.datafield andextraWhat are the differences between the fields? Do they all contain content?
datais inarchive/detailThe core data returned by the interface mainly includes the main content of the document, that is,contentField, typically the detailed article or product description edited by a rich text editor.extra字段则用于存储所有通过安企CMS后台“模型管理”功能为特定文档模型添加的 EnglishCustom fields。换句话说, Englishdata.content是文档的主要内容块, EnglishextraThen it is supplementary and structured data around this main content block.