你在这里学习Symfony邻居,
我在我的控制器上通过Ajax调用一个选择更改的方法。 我设法获取我发送给控制器的数据,但是当我尝试使用我得到的数据进行选择时,我很挣扎,出于某种原因,无论我决定返回的现有列,我得到一个& #34; specifiedColumn 未定义"我无法弄清楚原因。
这是我的方法:
public function getPricesAction(Request $request)
{
$first = $request->request->get('first');
$final = $request->request->get('final');
$em = $this->getDoctrine()->getManager();
//not too sure about stacking 2 setParameter here, guess there's a better way. But even if I just use one parameter, I still get the same error 'id is not defined'.
$getPrice = $em->createQuery('SELECT id FROM CarsBundle:Travel t WHERE t.first = :tst and t.final = :tfi')->setParameter('tre', $first)->setParameter('tra', $final);
$result = $getPrice->getResult();
return new JsonResponse($result);
}
我正在使用Symfony 3.3
感谢您的帮助!
答案 0 :(得分:1)
$getPrice = $em->createQuery('SELECT id FROM CarsBundle:Travel t WHERE t.first = :tst and t.final = :tfi')->setParameter('tre', $first)->setParameter('tra', $final);
应该是:
$getPrice = $em->createQuery('SELECT id FROM CarsBundle:Travel t WHERE t.first = :tst and t.final = :tfi')->setParameter('tst', $first)->setParameter('tfi', $final);
您的参数名称错误