joomla5.1 api接口修改 api/index.php/v1/content/articlescontroller中过滤条件filter.id无效如何处理

需求:项目中需要根据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

  • 22
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值