需求:项目中需要根据articles文章扩展字段查询要求的数据。
例:扩展字段名 province 省份,filed_id=1 pre_fields 中有一条扩展字段信息。
新增一条文章,文章ID/item_id=1,所属省份province 选择 重庆市,pre_fields_values 中有一个关联记录。
现在查询所属省份 重庆市 的所有文章 同时分页。
自带的接中有,api/index.php/v1/content/articles 这个接口有以下参数:
filter数组(过滤参数)
filter[language]=en&filter[province]=1
language 语言
province 省份ID(扩展字段)
list数组(排序参数)
list[ordering]=id&list[direction]=asc
list ordering 排序字段 direction 升序ASC降序DESC
page数组(主要是分页参数)
page[offset]=0&page[limit]=20
offset查询起始值 limit每页数量 分别就是mysql sql语句中 : select * from tabelname limit offset,limit;
api/index.php/v1/content/articles 直带接口 没有找到 搜索扩展字段的方式,只有重新写一个articlesController;
重写一个:api/index.php/v1/content/articlesa articlesa 命名添加了一个a。
api\components\com_content\src\Controller 文件夹中新增 articlesaController.php。
api\components\com_content\src\View 文件夹中新增 articlesa 文件夹,在里面创建JsonapiView.php;
注意:要使新接口生效:api/index.php/v1/content/articlesa 需要添加路由。
“根目录\plugins\webservices\content\src\Extension\Content.php” 文件中添加
articlesaController.php 中 function displayList() 对写自已的处理逻辑,添加过滤文章条件,例如限制ID。
$this->modelState->set(‘filter.id’, f i l t e r − > c l e a n ( filter->clean( fi