QueryParam的Symfony2 FOSRestBundle要求

时间:2014-03-04 11:37:19

标签: rest symfony

我有以下注释方法:

/**
 * Search on players.
 *
 * @ApiDoc(
 *   output = "bbb\FrontendBundle\Entity\Player",
 *   statusCodes = {
 *     200 = "Returned when successful",
 *     404 = "Returned when no result was found"
 *   }
 * )
 *
 * @Annotations\QueryParam(name="searchterm", requirements="[a-z]+", nullable=false, description="The term to search about in players.")
 * @Annotations\QueryParam(name="limit", requirements="\d+", default="3", nullable=true, description="How many results to return.")
 *
 * @param Request $request the request object
 * @param $searchterm
 * @param $limit
 * @return array
 * @throws NotFoundHttpException when no result was found
 *
 * @Method("GET")
 * @Route("/search", name="_api_player_search", options={"expose"=true})
 */
public function searchPlayerAction(Request $request, $searchterm, $limit)
{
}

问题是,如果我将例如“Aaron”作为searchterm(api/player/search?searchterm=Aaron)给出,则变量$ searchterm为null。如果我尝试api/player/search?searchterm=aaron一切正常。我猜问题是QueryParam注释的requirements="[a-z]+"属性。如何配置大写字母也是允许的?

(与空格等相同..)

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

尝试将requirements="[a-z]+"更改为requirements="[a-zA-Z]+"