Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:对Codeigniter中的非对象调用成员函数result()_Php_Codeigniter - Fatal编程技术网

Php 致命错误:对Codeigniter中的非对象调用成员函数result()

Php 致命错误:对Codeigniter中的非对象调用成员函数result(),php,codeigniter,Php,Codeigniter,致命错误:在第111行的D:\wamp\www\ocss\application\core\My\u 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

致命错误:在第111行的D:\wamp\www\ocss\application\core\My\u 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_模型,它有表名和get方法来获取所有结果

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;
}
在型号中

public function get_data()
{
    $query = $this->db->get('cake'); # get data from table
    $result = $query->result_array(); # re-Assign as objective array
    return $result; # return data
}

最后,我通过调用mysql查询而不是存储过程解决了我的问题

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("My Query To Database")->result_array();
        $material = $this->Material_Model->get(); // now when i call it here there is no error
    }
}

但当调用存储过程而不是查询时,我不清楚我的错误的严重性,
库存
函数的结果是什么?探索
$this->db->query(“调用库存($id)”)
值,在您的情况下可能是
TRUE
,而不是object。由
$material
行库存生成的错误是mysql中的过程
$inventory=$this->db->query(“调用库存($id)”->结果数组()此行我调用的是mysql过程;获取我的材料后,我将材料模型加载到自动加载配置文件Inside
材料模型
扩展我的材料模型所有数据库字段和表名中。在My_模型中的
get
方法中,它从数据库中获取所有记录,生成并返回对象数组
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("My Query To Database")->result_array();
        $material = $this->Material_Model->get(); // now when i call it here there is no error
    }
}