0
我想基於從請求中傳入的多個值對一個表執行簡單查詢,並且缺少對於更有經驗的人員來說顯而易見的事情。Doctrine QueryBulider語法錯誤
這不起作用:
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爲對象,布爾/應用程序/ MAMP/htdocs中/路徑/供應商/教義/ 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();
}
什麼我沒有到u nderstand?
它必須是' - > where('d.locationid =:locationid AND d.kfType =:kfType')' –
啊,謝謝!它現在有效。 – manisha