我想為我的專案實作端點的版本控制。事實證明 FOSRestBundle 的實作不是很清楚,所以我想實作如下:
Symfony 5.4
FOSRestBundle 3
請參閱下面的 annotation.yaml 檔案:
v2_controllers:
resource: ../../src/Controller/V2/
type: annotation
prefix: /v2
name_prefix: 'api_v2_'
controllers:
resource: ../../src/Controller/
type: annotation
name_prefix: 'api_'
kernel:
resource: ../../src/Kernel.php
type: annotation
當我運行此命令時,php bin/console debug:router --show-controllers
我得到以下結果:
..
..
...
api_offer_list GET ANY ANY /offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
api_v2_offer_list GET ANY ANY /v2/offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
...
..
您可以看到,由于一些奇怪的原因,新版本也覆寫了舊端點
最后是我的 fos_rest.yaml 配置:
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
param_fetcher_listener: true
uj5u.com熱心網友回復:
在控制器目錄中,您需要創建兩個單獨的目錄,一個用于 v1,另一個用于 v2,這應該可以解決問題。
Controller/
v1/
v2/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/417612.html
標籤:
上一篇:如何驗證服務層中的資料?
