我正在尝试根据从请求中传入的多个值对一个表进行简单查询,并且遗漏了一些对更有经验的人来说显而易见的东西。
这不起作用:
public function showAction(Request $request)
{
if ($request->getMethod() == 'GET') {
$id = $request->get('locationid');
$kfType = $request->get('type');
$em = $this->getDoctrine()
->getManager();
$data = $em->createQueryBuilder()
->select('d')
->from('DashDataBundle:Data', 'd')
->where('d.locationid = :locationid' AND 'd.kfType = :kfType' )
->setParameters(array('locationid'=> $id,'kfType'=> $kfType))
->setMaxResults(100)
->getQuery()
->getResult();
}
错误是:
警告:get_class() 期望参数 1 是对象,布尔值在 /Applications/MAMP/htdocs/path/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Expr/Base.php 第 89 行中给出
但是,这仅适用于一个参数:
public function showAction(Request $request)
{
if ($request->getMethod() == 'GET') {
$id = $request->get('locationid');
$kfType = $request->get('type');
$em = $this->getDoctrine()
->getManager();
$data = $em->createQueryBuilder()
->select('d')
->from('DashDataBundle:Data', 'd')
->where('d.locationid = :locationid')
->setParameter('locationid', $id)
->setMaxResults(100)
->getQuery()
->getResult();
}
我不明白什么?