I am doing the codecourse php oop login/register tutorial and have run into some trouble. The issue I am having is with these lines:
$user = new User();
$login = $user->login(Input::get('username'), Input::get('password'));
These run conditionally on validation passing, which it does, because it returns no errors. I want to make this as simple as possible and don't think I need to include too much code because I think I have narrowed down the problem.
This is the code in my user class for the login function
public function login($username = null, $password = null) {
$user = $this->find($username);
print_r($this->_data);
if($user) {
if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
echo 'OK!';
} else {
echo '<br>';
echo 'This data password:';
var_dump($this->data()->password);
}
}
return false;
}
I know that my data is being retrieved, because I run print_r on ($this->data) and it returns the proper info for the user. So although my data is being retrieved, I think this is what is causing my error. This is the result of my print_r after failing to log in
Array ( [0] => stdClass Object (
[id] => 32
[email] => xxx
[fname] => xxx
[lname] => xxx
[username] => user
[password] => 295c7ac2341f2688838148728d450a5562933d5fbea6d2a9e9fec2eeab29dd84
[salt] => 4ÌxÇd”0ð&ÞðÈßr¡–k$ «%•¦S?~d$r
[name] => xxx
[joined] => 2016-09-28 07:10:32
[grouptype] => 1 ) )
The reason my $user->login method is not working is because the user is not an object, rather an array of the object (or at least that is what I have hypothesized) after finding a semi working version of the code (login works, register does not) that returns the same data without the
Array ( [0] => stdClass Object
and is instead just simply
stdClass Object ( [id] =>
Why is my object inside of an array?