2017-08-02 63 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