【发布时间】:2015-12-12 19:48:23
【问题描述】:
致命错误:在第 111 行对 D:\wamp\www\ocss\application\core\My_Model.php 中的非对象调用成员函数 result()
class Report extends MY_Controller{
public function item_ladger()
{
$material = $this->Material_Model->get(); // when i call it here it works fine
$inventory = $this->db->query("CALL inventory($id)")->result_array();
$material = $this->Material_Model->get(); // when i call it here it Generate Fatal error: Call to a member function result() on a non-object in
}
}
背后的原因是什么?
编辑
这是我的材料模型,它有表名和所有表字段
class Material_Model extends MY_Model
{
const DB_TABLE = 'material';
const DB_TABLE_PK = 'material_id';
public $material_id;
public $material_name;
public $size;
public $rate;
}
这是我的 MY_Model,它有表名和获取所有结果的方法
class MY_Model extends CI_Model {
const DB_TABLE = 'abstract';
const DB_TABLE_PK = 'abstract';
public function get($limit = 500, $offset = 0,$desc=true) {
if ($limit) {
if ($desc)
$query = $this->db->order_by($this::DB_TABLE_PK, 'DESC')->get($this::DB_TABLE, $limit, $offset);
else
$query = $this->db->get($this::DB_TABLE, $limit, $offset);
}
else {
$query = $this->db->get($this::DB_TABLE);
}
$ret_val = array();
$class = get_class($this);
foreach ($query->result() as $row) {
$model = new $class;
$model->populate($row);
$ret_val[$row->{$this::DB_TABLE_PK}] = $model;
}
return $ret_val;
}
【问题讨论】:
-
inventory函数的结果是什么?探索$this->db->query("CALL inventory($id)")值,在你的情况下可能是TRUE,而不是对象。 -
$material行库存产生的错误是 mysql 中的过程
标签: php codeigniter