0
votes

i have entity Collab that extend from Fos\UserBundle\Model\User, i want to get the entity from the username that i login . i my controller :

      echo $this->getUser();
    $collab->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser());
    echo $this->getEmailCollaborateur();

in my manager i defined i method :

   public function findCollaborateurByUserName ($username){
    return $this->getRepository()->findOneBy(array('username'=>$username));
}

i get this exception :

FatalErrorException: Error: Call to a member function get() on a non-object in 

how can get this entity??

2

2 Answers

0
votes

What is $collab? You're getting Fatal Error trying to call get method on variable that was not properly initialized (non-object).

0
votes

Your problem is in this lines:

return $this->getRepository()->findOneBy(array('username'=>$username));
$collab->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser());

It should be:

return $this->getDoctrine()->getRepository('YourBundleNamespace:Collab')->findOneBy(array('username'=>$username));
$collab = $this->get('collab.collaborateurservice')->findCollaborateurByUserName($this->getUser()->getUsername());