1 回答
TA贡献2036条经验 获得超8个赞
我找到了解决我的问题的方法。看来 API 平台文档毕竟离答案不远了!在资源配置文件中尝试了一段时间后,终于决定给这个services.yaml文件一个机会。我在这个 github 问题上得到了很大帮助。所以,这就是我所做的。
第 1 步 -在services.yaml:
# filters
app.customer_resource.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'firstname': 'partial', 'lastname': 'partial', 'emailAddress': 'partial', 'owner.emailAddress': 'exact' } ]
tags: [ { name: 'api_platform.filter', id: 'customer.search_filter' } ]
autowire: false # required, explained below
autoconfigure: false # required, explained below
注0:在autowire和autoconfigure参数都在这里需要的,否则你会得到一个错误:
当设置了“parent”时,服务“app.customer_resource.search_filter”上的属性“autowire”/“autoconfigure”不能从“_defaults”继承。将您的子定义移动到单独的文件或在 [...] 中明确定义此属性(在资源“[...]”中加载)。
注 1:我注意到这里最重要的元素是“tags”参数的“id”元素。在我寻找解决方案时,我发现了,这表明您必须提供过滤器 ID 才能使其工作。在第 2 步中亲自查看。vendor/api-platform/core/src/Swagger/Serializer/DocumentationNormalizer::getFilter()
第 2 步 -在您的资源配置文件中(我的在config/resources/customer.yaml)
App\Entity\Customer:
collectionOperations:
get:
filters: ['customer.search_filter']
# ...
我刚刚通过使用(如我所说的)重要过滤器 ID为 GET 收集操作添加了过滤器。所以,这解决了我的问题。但是,如果有人有更好/更简单的解决方案,我很高兴知道。
- 1 回答
- 0 关注
- 263 浏览
添加回答
举报
