Mixing route and query parameters using FOSRestBundle with Symfony

前端 未结 2 1209
-上瘾入骨i
-上瘾入骨i 2021-02-05 23:27

Using Symfony2 and FOSRestBundle I am attempting to implement API methods that have some number of fixed parameters defined in the route along with some optional parameters that

2条回答
  •  生来不讨喜
    2021-02-06 00:02

    Just wanted to post an answer because the original answer only uses QueryParams, and the question was using QueryParams together with RouteParams.

    If you want to use route params and query params, you can use the ParamFetcher as first argument to the action and add the route arguments later.

    I have not yet found a way to add the route params to the paramFetcher.

    /*
     * @Route("/term/{termId}", requirements={"termId" = "[a-z0-9]+"})
     *
     * @QueryParam(name="limit", requirements="\d+", default="30", description="How many documents to return.")
     *
     * @Method("GET")
     *
     * @param ParamFetcherInterface $paramFetcher
     * @param $termId
     * @return array()
     */
    public function getTermFeedAction(ParamFetcherInterface $paramFetcher, $termId) {
        // access $termId over the method parameter
        // access the @queryparams via the $paramFetcher
    
    }
    

提交回复
热议问题