I am having a similar problem to this question on stackoverflow. The error I am receiving is
Call to a member function validatePassword() on a non-object
On my Users model I am using findOne()
method to return the User object. When I try to validate user using this method on my LoginForm method I receive the error I have stated.
public function getUserStatus()
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if($user || $user->validatePassword($this->password)) {
if($user->user_status == 0) {
return 1;
} else {
return 8;
}
} else {
return -1;
}
}
}
My getUser is the same as the one on Yii2 advanced template.
public function getUser()
{
if ($this->_user === false) {
$this->_user = Users::findByEmail($this->email, self::USER);
}
return $this->_user;
}
The problem I am facing is that when calling this there is no error:
if(!$user || !$user->validatePassword($this->password))
This however has an error:
if($user || $user->validatePassword($this->password))
How is this as I believe it has got to do with PHP objects itself rather than the framework?