Symfony [语义错误] 'id' 未定义

Symfony [Semantical Error] 'id' is not defined

这里是你学习 Symfony 的邻居,

我在 select 更改时通过 Ajax 从我的控制器调用一个方法。 我设法获取了发送到控制器的数据,但由于某种原因,无论我决定 return,我得到一个“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

感谢您的帮助!

$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);

你输入的参数名称有误