-4

I am trying to call to the email of a user in my function but i keep getting this error:

Error: Call to a member function getEmail() on a non-object

I am sure that the problem isn't from the entity, but I am confused why this method isn't working (I have used it before and it worked).

here is the function I am working on:

public function registerAction($email,$password,$token)
{
    $em = $this -> getDoctrine();
    $user = $em -> getRepository("OBCarsTest2Bundle:user") ->findOneBytoken($token);

if($user == Null)
{
    if(strcmp($user->getEmail(),$email) != 0)
    {
        $newUser = new user();
        $factory = $this->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $token = md5(uniqid($email, true));
        $pass = $encoder->encodePassword($password, $user->getSalt());
        $newUser->setEmail($email);
        $newUser->setPassword($pass);
        $newUser->setIsActive(1); //enable or disable
        $newUser->setToken($token);
        $UId = $newUser->getId();
    }
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
daroum
  • 59
  • 14

1 Answers1

2

Wrong check. If $user is empty then there will be nothing like getEmail() for $user. Should be -

if($user != Null)

OR

if(!empty($user))
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87