Apologies for posting this question - I know they have been asked and answered several times (i.e. https://stackoverflow.com/questions/1787561/call-to-a-member-function-on-a-non-object, etc), but non of the suggested solutions seem to work for me. This is what I have:
class Common {
private $model;
public function _construct() {
$this->model = Model::GetInstance();
//$this->model->GetUserCollection();
}
public function validateusername($username) {
$userlist = $this->model->GetUserCollection();
$result = true;
if ($username == false) {
$this->error = "Please enter username.";
$result = false;
}
}
}
// This is my DB model
class Model {
private static $instance = null;
private $conn = false;
private function __construct() {
if (!$this->connect()) {
print "Unable to connect to database!";
exit;
}
}
public function connect() {
if ($this->conn == false) {
$this->conn = mysql_connect(DBHOST, DBUSER, DBPASS);
if ($this->conn) {
if (!mysql_select_db(DBNAME, $this->conn)) {
print "DB Connection Error!";
exit;
}
}
}
return $this->conn;
}
public function GetUserCollection() {
return UserCollection::GetInstance();
// return new UserCollection();
}
public static function GetInstance() {
if (!self::$instance) {
self::$instance = new Model();
}
return self::$instance;
}
}
Why is it exactly this line : $userlist = $this->model->GetUserCollection(); which is throwing me an error even though I am returning a new instance of it in the in the model Thanks in advance, JJ.