我正在尝试使用教义进行动态搜索查询。它不工作
$em = $this->getDoctrine()->getEntityManager();
$city = 'new york';
$minprice = 500;
$maxprice = 1000;
$testquery = "SELECT p FROM AcmeTestBundle:Car p WHERE p.city = :city";
$testparam = array('city' => $city,);
if ($minprice != '') {
if ($maxprice != '') {
$testquery .= " and p.price BETWEEN :minprice AND :maxprice";
$testparam .= array(
'minprice' => $minprice,
'maxprice' => $maxprice,
);
}
}
$testquery .= " ORDER BY p.price ASC";
$query = $em->createQuery($testquery)->setParameters($testparam);
$result = $query->getResult();
有一个更好的方法吗?