我正在使用 Symfony 4 和 API 平台构建客户关系管理 API 以供练习。我已经学到了很多关于 API 平台的知识,即使我可以使用注解进行资源配置,我还是强迫自己使用 YAML 以了解更多信息。
所以,我有哪几种属性的客户资源:ID,姓名,姓氏,EMAILADDRESS,公司,createdAt,updatedAt和所有者。我的目标是在这个资源上添加一个SearchFilter(在 YAML 中)并将大多数属性添加为这个过滤器的属性。
我已经尝试过这里给出的解决方案:https : //github.com/api-platform/core/issues/1755。问题是我无法让它发挥作用。在 services.yaml 中,我看到您可以添加参数,但我不知道您可以在注释中找到什么等效项...
在config/services.yaml:
# filters
app.my_filter:
parent: 'api_platform.doctrine.orm.search_filter'
tags: ['api_platform.filter']
autowire: false
autoconfigure: false
public: false
在resources/customer.yaml:
App\Entity\Customer:
collectionOperations:
get:
normalization_context:
groups: ['Customer:Get']
filters: ['app.my_filter']
我打算做的是类似于以下的注释src/Entity/Customer.php:
/**
* @ApiResource
*
* [...]
*
* @ApiFilter(SearchFilter::class, properties={
* "firstname": "partial",
* "lastname": "partial",
* "emailAddress": "partial",
* "company": "partial"
* })
*/
class Customer
{
...
}
我希望你能提供帮助,我的问题得到了清楚的解释。如果没有,请告诉我,我会尽力为您提供更多详细信息。
三国纷争
慕桂英3389331
随时随地看视频慕课网APP