0
に呼び出そうとしました
エンティティ "Vehicules"は、エンティティ "User"とManyToOne関係にあります。したがって、各ユーザーは1つ以上の車両を所有しています。私はforeachユーザーの台数を数え、それをテーブルに表示しようとしています。 これはこれは私がvehicules foreachのユーザー(方向)の数をカウントし、私が得るクラス "createQueryBuilder"をクラス
public function afficheAction() {
$em = $this->getDoctrine();
$demandes = $em->getRepository('DemandevehBundle:Demande')->findAll();
// trying to count the number of vehicules foreach direction
$vehicules = $this->getDoctrine()->getRepository('CarPfeBundle:Vehicule')->findAll();
foreach($vehicules as $vehicule) {
$qb = $vehicule->createQueryBuilder('v');
$qb->select('count(v.id)');
$qb->where('v.direction = ?1');
$qb->setParameter('1', $vehicule->getId());
$query = $qb->getQuery();
$result = $query->getSingleScalarResult();
return $result;
}
// fin
return $this->render('DemandevehBundle:Demande:affiche.html.twig', array('demandes' => $demandes
,'result' => $result));
}
テーブルにそれを表示したい機能がある
/**
* @ORM\ManyToOne(targetEntity="OC\UserBundle\Entity\User")
* @ORM\JoinColumn(name="User_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $direction;
VEHICULE
私のエンティティの一部でありますこのエラーAttempted to call method "createQueryBuilder" on class "Car\PfeBundle\Entity\Vehicule".
私はこのエラーが発生する理由が私の機能は意味をなしません。助けてください?
実際に私は、それがどのように役立つ可能性が混乱しています。より多くのspeceficするために私は "$ vehicule-> getId()"を "5"に変更したので、ただ1つの変数にしようとしましたが動作しますが、私はどのようにそれを行うことができますか? –