【发布时间】:2017-05-19 23:40:57
【问题描述】:
我真的可以在不创建模型的新实例的情况下进行数据库查询吗?
例如,在我的控制器中,我有 (CONTROLLER)
Name_Model::get_all_from_another_table();
并以我的名字_model.php (MODEL)
public static function get_all_from_another_table() {
$this->db->query('select * from another_table');
return $x;
}
在创建新模型实例之前加载具有预定义值的表会发生这种情况。
以上代码返回:
Fatal error: Using $this when not in object context
【问题讨论】:
-
你为什么不试试
$this->load->model('name_model')?在控制器上执行此操作。我们应该使用$this->name_model->get_all_from_another_table()来调用它。 -
@Ukasyah
Fatal error: Using $this when not in object context。发生同样的错误。 -
我认为我们在函数上使用“静态”时不能使用 $this
标签: php mysql database codeigniter