例外をスローしている次のコードがありますInvalid parameter number: number of bound variables does not match number of tokens
。しかし、登録したパラメータを印刷すると、パラメータが表示されます。
public function getUnitPriceFor($entityType,$entityID,$qty,$configuration_id)
{
$this->qb = $this->getEntityManager()->createQueryBuilder();
$this->qb ->select($this->_entities[$entityType]['select'])
// for Base this would be ->select(array('t','c','w','g'))
// for the other cases below, like website, it's array('t','w')
->from('AcmeBundle:PriceTier', 't');
switch($entityType) :
case 'base' :
$this->qb ->leftJoin('t.customers','c')
->leftJoin('t.customergroups','g')
->leftJoin('t.websites','w');
break;
case 'website' :
$this->qb ->join('t.websites','w','WITH','w.id = '.$entityID);
break;
case 'custgrp' :
$this->qb ->join('t.customergroups','g','WITH','g.id = '.$entityID);
break;
case 'cust' :
$this->qb ->join('t.customers','t','WITH','t.id = '.$entityID);
break;
endswitch;
$this->qb ->where('t.printconfiguration = :configuration_id');
$this->qb ->setParameter('configuration_id', $configuration_id);
print_r( $this->qb->getParameters() );
$dql = $this->qb->getDQL();
echo"<pre>";
print_r($this->getEntityManager()->createQuery($dql)->getArrayResult());
echo"</pre>";
}
印刷すると、が$this->qb->getParameters();
表示Array ( [configuration_id] => 1 )
され、where句とsetパラメータ句を削除すると、例外が発生しなくなります。最後に(そしてこれを取得して)、where句を削除してもパラメータを設定したままにすると、例外は発生しません。私はかなり混乱しています。