Doctrine 2 を使用して、別のユーザーの連絡先であるユーザーを取得したいと考えています。テーブルuser
には、これらのユーザー間のマッピングが含まれています。関数内のクエリは次のエラーを返します。
パラメータ番号が無効です: バインドされた変数の数がトークンの数と一致しません。
ただし、私の理解$str
では、「b」に$ownerId
設定され、「2」に設定されており、両方がsetParameters
関数によって割り当てられています。
protected function getContactBySubstring($str, $ownerId) {
echo $str;
echo $ownerId;
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->add('select', 'u')
->add('from', '\Paston\VerBundle\Entity\User u, \Paston\VerBundle\Entity\Contact c')
->add('where', "c.owner = ?1 AND c.contact = u.id AND u.username LIKE '?2'")
->add('orderBy', 'u.firstname ASC, u.lastname ASC')
->setParameters(array (1=> $ownerId, 2=> '%'.$str.'%'));
echo $qb->getDql();
$query = $qb->getQuery();
$users = $query->getResult();
foreach($users as $user)
echo $user->getUsername();
exit;
//return $contacts;
}