在过去的 2 个小时里,我试图找到解决我的错误的方法。我正在尝试从特定表中检索条目,但它总是说
致命错误:在第 18 行的 web_performance/models/MongoDbConnection.php中的非对象上调用成员函数 find()
有什么建议该怎么做?
这是我的数据库连接类
class MongoDbConnection {
private $_mongoDb=null;
private $_table;
public function __constructor($dbAddress='localhost') {
$this->_mongoDb=new Mongo($dbAddress);
}
public function setTable($argTableName){
$this->_table=$this->_mongoDb->$argTableName;
return $this;
}
//select method
public function find(){
$this->_table->find(); // <- Line 18
return $this;
}
//create insert method
/*public function insert($values){
$this->_table->insert($values);
return $this;
}*/
//update method
public function update($values){
$this->_table->update($values);
return $this;
}
//delete method
public function dbMongoDelete($values){
throw new Exception('Delete not yet defined in '.__CLASS__);
}
//end class
}
这是我的设置类
module_load_include('php', 'web_performance', 'models/MongoDbConnection');
class BenchmarkingSettings {
private $_mongoDb;
static private $_instance;
public function __construct() {
$this->_mongoDb=new MongoDbConnection();
}
static public function getInstance() {
if (is_null(self::$_instance)) {
self::$_instance=new BenchmarkingSettings();
}
return self::$_instance;
}
public function populateFormWithValueSettings(){
$response=$this->_mongoDb->setTable("benchmarkingSettings")->find();
return $response;
}
}