我无法使用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
作为回复