[英]Symfony2's relation one-to-many
I have two tables.我有两张桌子。 First table is stat_alert and second is user_qdf.
第一个表是 stat_alert,第二个是 user_qdf。 i have a relation many to one between tables
我在桌子之间有一个多对一的关系
I want to assign the value in the foreign key table in my controller :我想在我的控制器的外键表中分配值:
$sql9="SELECT cell,id_user FROM stat_alert WHERE TYPE='C' AND id_user IS NULL LIMIT $purcent ";
$h = mysql_query($sql9)OR DIE("Erreur sur la requeteee");
$listes9 = array();
while ($row = mysql_fetch_array($h)) {
$listes9[] = $row;
}
foreach ($listes9 as $liste9 )
{
$user_qdf = $this->getDoctrine()
->getRepository('AdminBlogBundle:UserQdf')
->find($cs);
echo $liste9[0];
$em = $this->getDoctrine()->getEntityManager();
$alert = $em->getRepository('AdminBlogBundle:StatAlert')
->findBy(array('cell' => $liste9[0]));
**$alert->setUser($user_qdf);**
$em->flush();
}
i have this error Fatal error: Call to a member function setUser() on a non-object in D:\\EasyPHP-5.3.3.1\\www\\alerteurs1\\src\\Admin\\BlogBundle\\Controller\\GestionAlerteController.php on line 514我有这个错误致命错误:调用成员函数 setUser() 在 D:\\EasyPHP-5.3.3.1\\www\\alerteurs1\\src\\Admin\\BlogBundle\\Controller\\GestionAlerteController.php 上的第 514 行
findBy()
returns a collection, not a object. findBy()
返回一个集合,而不是一个对象。 Use findOneBy()
instead and it should be ok.改用
findOneBy()
应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.