2017-08-02 32 views
0

我想在我的symfony控制器上使用QueryParam。具有空值的Symfony QueryParam

問題是我不想接受查詢中的空參數。但是,當我定義與

@REST\QueryParam(name="test" , description="The test", requirements="\w+", strict=true, nullable=false) 

的QueryParam,我嘗試用mysite.com/test=它仍在努力調用Web服務。

什麼,我需要做的拒絕請求空PARAM沒有代碼的測試,如果參數是空的或不

謝謝

回答

0

當測試古怪足夠的驗證似乎沒有一起工作配置param_fetcher_listener只需true,但是當我用force,突然一切工作:

# config.yml 
fos_rest: 
    param_fetcher_listener: force 

和Controller:

/** 
* @QueryParam(name="test" , description="The test", requirements="[a-zA-Z]+", strict=true, nullable=false, allowBlank=false) 
*/ 
public function indexAction($test) 
{ 
    // replace this example code with whatever you need 
    return new JsonResponse($test); 
} 

請注意,在我的例子中有多個驗證,只有?test=a將工作。否test,?test=?test=1都將因指定的原因而不工作。

如果有人知道如何得到它與param_fetcher_listener: true我很好奇:)

另請參閱使用force

+0

謝謝您的回答的含義的文檔(https://symfony.com/doc/master/bundles/FOSRestBundle/param_fetcher_listener.html), 問題工作當我嘗試添加'allowBlank = false'時,我有一個錯誤,我正在與symfony 2.8 – Hussein

+0

工作最後它的工作,我更新/ rest-bundle到1.5 :)一切工作都知道:) – Hussein