0
votes

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 ?

1
$doc isn't an object. var_dump it and see what it really is.Jonnix
Are you sure the line 88 is were you marked it ? Normally you can't do $res->getId() with getArrayResult .Alsatian
Yes, I'm sure about line 88, when I did getResult it crashs my navigator, any idea ?Euphor08
check php errors for the crashing causeabdiel

1 Answers

0
votes

Clearing the cache resolve my issue. the command is :

php app/console cache:clear