过去2小时内,我正在尝试找到错误的解决方案。我试图从特定的表中检索条目,但它总是说
致命错误:在中的非对象上调用成员函数find() 第18行的web_performance / models / MongoDbConnection.php
有什么建议吗?
这是我的数据库连接类
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;
}
}
答案 0 :(得分:1)
更改此
public function __constructor($dbAddress='localhost') {
到
public function __construct($dbAddress='localhost') {