第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 YAML 中使用 API 平臺(tái)過濾器?

如何在 YAML 中使用 API 平臺(tái)過濾器?

PHP
三國紛爭 2021-09-05 16:30:52
我正在使用 Symfony 4 和 API 平臺(tái)構(gòu)建客戶關(guān)系管理 API 以供練習(xí)。我已經(jīng)學(xué)到了很多關(guān)于 API 平臺(tái)的知識(shí),即使我可以使用注解進(jìn)行資源配置,我還是強(qiáng)迫自己使用 YAML 以了解更多信息。所以,我有哪幾種屬性的客戶資源:ID,姓名,姓氏,EMAILADDRESS,公司,createdAt,updatedAt和所有者。我的目標(biāo)是在這個(gè)資源上添加一個(gè)SearchFilter(在 YAML 中)并將大多數(shù)屬性添加為這個(gè)過濾器的屬性。我已經(jīng)嘗試過這里給出的解決方案:https : //github.com/api-platform/core/issues/1755。問題是我無法讓它發(fā)揮作用。在 services.yaml 中,我看到您可以添加參數(shù),但我不知道您可以在注釋中找到什么等效項(xiàng)...在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{...}我希望你能提供幫助,我的問題得到了清楚的解釋。如果沒有,請(qǐng)告訴我,我會(huì)盡力為您提供更多詳細(xì)信息。
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊

我找到了解決我的問題的方法。看來 API 平臺(tái)文檔畢竟離答案不遠(yuǎn)了!在資源配置文件中嘗試了一段時(shí)間后,終于決定給這個(gè)services.yaml文件一個(gè)機(jī)會(huì)。我在這個(gè) 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參數(shù)都在這里需要的,否則你會(huì)得到一個(gè)錯(cuò)誤:


當(dāng)設(shè)置了“parent”時(shí),服務(wù)“app.customer_resource.search_filter”上的屬性“autowire”/“autoconfigure”不能從“_defaults”繼承。將您的子定義移動(dòng)到單獨(dú)的文件或在 [...] 中明確定義此屬性(在資源“[...]”中加載)。


注 1:我注意到這里最重要的元素是“tags”參數(shù)的“id”元素。在我尋找解決方案時(shí),我發(fā)現(xiàn)了,這表明您必須提供過濾器 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 收集操作添加了過濾器。所以,這解決了我的問題。但是,如果有人有更好/更簡單的解決方案,我很高興知道。


查看完整回答
反對(duì) 回復(fù) 2021-09-05
  • 1 回答
  • 0 關(guān)注
  • 186 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)