I had a problem in Symfon2, which is :
Error: Call to a member function getId() on a non-object in /var/www/UserBO/src/BO/UserBundle/Controller/DefaultController.php line 88
Entity Form contains many entity docs, my code is :
public function userAction()
{
$data = array();
$row = array();
$extra = array();
$results = $this->getDoctrine()->getRepository("BOUserBundle:Form")->createQueryBuilder('q')->getQuery()->getArrayResult();
// var_dump($results); die;
foreach ($results as $res){
$row = array(
'id' => $res->getId(),
'name' => $res->getName(),
'adresse' => $res->getAdresse()
);
$docs = $this->getDoctrine()->getRepository("BOUserBundle:Document")->find($res->getId());
foreach ($docs as $doc)
{
$extra[] = array(
'id'=> $doc->getId(), **// line 88**
'name doc'=> $doc->getName(),
'path' => $doc->getPath()
);
}
$row = array_merge($row, array('docs'=>$extra));
}
// var_dump($data); die;
$data[] = $row;
return new JsonResponse($data);
//return $this->render('BOUserBundle:Default:user.html.twig', array('data' => $data));
}
thank's
EDIT :
$results = $this->getDoctrine()->getRepository("BOUserBundle:Form")->createQueryBuilder('q')->getQuery()->getResult(); var_dump($results); die;
Using getResult it blocks the navigator (Mozilla), and getArrayResult() it's not,so what's the problem ?
$doc
isn't an object.var_dump
it and see what it really is. – Jonnix