I get the above error even though the data() method is defined in my user class. I want to be able to echo the user's details on the index page. The index.php code below where I instantiated the user class
<?php
$user = new User();
echo $user->data()->email;
The user class below: User.php
<?php
class User {
private $_db,
$_data,
$_sessionName,
$_details,
$_isLoggedIn;
public function __construct($user = null) {
$this->_db = DB::getInstance();
$this->_sessionName = Config::get('session/session_name');
if (!$user) {
if (Session::exists($this->_sessionName)) {
$user = Session::get($this->_sessionName);
if ($this->find($user)) {
$this->_isLoggedIn = true;
} else {
// process logout
}
}
} else {
$this->find($user);
}
}
public function create($fields = array()) {
if (!$this->_db->query("INSERT INTO users (firstname, othernames, surname, email, grup, password, salt, hash, joined) VALUES (?,?,?,?,?,?,?,?,?)", $fields)) {
throw new Exception('Could not register user');
}
}
public function find($user=null) {
if ($user) {
$field = (is_numeric($user)) ? 'id' : 'email';
$data = $this->_db->query("SELECT * FROM users WHERE email=?", array($user));
}
if ($data->count()) {
$this->_data = $data->first();
return true;
}
return false;
}
public function login($email = null, $password = null) {
$user = $this->find($email);
if ($user) {
//print_r($this->_data);
if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
if (!is_object($this->data())) {
die('ooo not objj');
} else {
echo "its obj";
}
Session::put($this->_sessionName, $this->data()->id);
return true;
}
}
return false;
}
public function data() {
return $this->_data;
}
public function isLoggedIn() {
return $this->_isLoggedIn;
}
public function details() {
return $this->_details;
}
}
The data() method is defined in the user class. Can figure where the error is coming from...