2013-08-20 66 views
1
public function search($params) 
    { 
     $qb = $this->createQueryBuilder('auto'); 
     if (isset($params['manufacturer'])) { 
      $qb->join('auto.manufacturer', 'man') 
      ->where('man.manufacturer = :manufacturer') 
      ->setParameter('manufacturer', $params['manufacturer']); 
     } 
     if (isset($params['model'])) { 
      $qb->join('auto.model', 'mod') 
       ->where('mod.model = :model') 
       ->setParameter('model', $params['model']); 
     } 

     return $qb->getQuery()->getResult(); 
    } 

查詢返回錯誤:多連接查詢生成器doctrine2

Invalid parameter number: number of bound variables does not match number of tokens

+0

你可以var_dump $ params? – AlterPHP

+0

array() 'manufacturer'=> string'Opel'(length = 4) 'model'=> string'45'(length = 2) – korvinko

回答

6

更換whereandWhere功能。因爲當你有2個參數時,你首先替換where條件,在第二個條件和結果中你只有一個標記有2個綁定參數。

相關問題