我想恢复写帖子的用户,只是我尝试这样做时出错“ Attempted to call an undefined method named "getIdPost" of class "App\Entity\User".
”
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery( //creation de la requête
'SELECT p , u
FROM App\Entity\User u, App\Entity\Post p
WHERE p.Id_Post_Parent IS NULL
AND p.Id_User = u.idUser
ORDER BY p.Post_Date_Time DESC'
)->setMaxResults(10);
$posts = $query->getResult();
$publicPosts = array();
$comments = array();
for($i = 0; $i<sizeof($posts) ; $i++){
$publicPosts[$i] = $posts[$i]->getArray();
//récupération des commentaires
$em = $this->getDoctrine()->getManager(); //on appelle Doctrine
$query = $em->createQuery( //creation de la requête
'SELECT p , u
FROM App\Entity\User u, App\Entity\Post p
WHERE p.Id_Post_Parent = :idParent
AND p.Id_User = u.idUser'
)->setParameter('idParent', $posts[$i]->getIdPost())
->setMaxResults(10); //On limite à 10 commentaires par posts
$comments[$i] = $query->getResult(); //variable qui récupère la requête
}
如果我删除查询的用户实体,它可以工作并且我没有错误......我不明白它是什么原因,为什么它告诉我用户中没有方法“getIdPost”?这是正常的,因为它是“发布”的一种方法:x