Symfony:从请求查询中获取参数

时间:2016-08-22 14:43:53

标签: php symfony doctrine

我无法使用Symfony实现搜索功能。这就是我所拥有的:

/**
 * CoffeeShop controller.
 *
 * @Route("/coffeeshops")
 */
class CoffeeShopController extends Controller
{

/**
 * @Route("/q?", name="api_coffeeshops_search")
 * @Method("GET")
 */
public function searchAction(Request $request){

    $chain = $request->query->get('chain');

    $result = new JsonResponse();
    $coffeeShops = $this->getDoctrine()
        ->getRepository('CoreBundle:CoffeeShop')->findBy(array('chain' => $chain));

    $result->setContent($coffeeShops);
    return $result;
}
}

当我提交查询时

 http://127.0.0.1:8000/api/v1/coffeeshops/q?chain=2

我只获得null作为回复

0 个答案:

没有答案