簡體   English   中英

Symfony2-后期參數要求

[英]Symfony2 - Requirements for post parameters

我是Symfony的新手,並使用FriendsOfSymfony RestBundle構建Rest API。

我的問題是我想將用於GET路由的要求用於POST路由。 有什么辦法嗎?

所以實際上是這樣的:

@Post("/article/{articleId}", requirements={"articleId"="\d+"})

顯然,ParamFetcher也僅適用於GET參數,盡管我找不到與此有關的任何特定信息。

對於這個主題的幫助,我將不勝感激。

ParamFetcher也可以與POST參數配合使用。 您可以使用注釋:

使用FOS \\ RestBundle \\ Controller \\ Annotations \\ RequestParam;

/**
 * @RequestParam(
 *   name="",
 *   key=null,
 *   requirements="",
 *   default=null,
 *   description="",
 *   strict=true,
 *   array=false,
 *   nullable=false
 * )
 */

請記住要啟用相關的偵聽器,否則它將不起作用:

fos_rest:
    param_fetcher_listener: true
    body_listener: true

參考和文檔在這里: https : //github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.md

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM