Php 在Symfony 3.4中验证通过querystring作为整数传入的可选输入GET参数
在Symfony 3.4中,是否有方法验证通过querystring作为整数传递的可选输入GET参数 如果提供,我将使用Php 在Symfony 3.4中验证通过querystring作为整数传入的可选输入GET参数,php,symfony,symfony-3.4,php-7.3,symfony-routing,Php,Symfony,Symfony 3.4,Php 7.3,Symfony Routing,在Symfony 3.4中,是否有方法验证通过querystring作为整数传递的可选输入GET参数 如果提供,我将使用$ownerId和$courseId查询相应的存储库,但是该值必须是整数,否则查询将失败 这就是我到目前为止所拥有的,它与文档匹配,但它似乎没有强制进行任何验证或优雅地处理传递?例如,ownerid=crmpicco&courseId=rfc1872 /** * @Route( * "/book-teeoff/{course}/{area}", * n
$ownerId
和$courseId
查询相应的存储库,但是该值必须是整数,否则查询将失败
这就是我到目前为止所拥有的,它与文档匹配,但它似乎没有强制进行任何验证或优雅地处理传递?例如,ownerid=crmpicco&courseId=rfc1872
/**
* @Route(
* "/book-teeoff/{course}/{area}",
* name = "book_teeoff",
* requirements={"ownerId"="\d+","courseId"="\d+"},
* methods={"GET"}
* )
*
* @param Request $request
*
* @return Response
*/
public function bookTeeoffAction(Request $request): Response
{
// these are *optional*, but if provided need to be integers
$ownerId = $request->get('ownerId');
$courseId = $request->get('courseId');
您可以使用更具体的getter,例如
$request->query->getInt('ownerId')
。这能解决你的问题吗?请参阅:需求定义用于路线的占位符(课程
和区域
)。当ownerId
和/或courseId
更清晰时,可以定义一个特定的路线?您可以使用一个很好的解决方案,但在这里运行验证听起来有点粗糙。