简体   繁体   English

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

[英]Fatal error: Call to a member function result() on a non-object in Codeigniter

Fatal error: Call to a member function result() on a non-object in D:\\wamp\\www\\ocss\\application\\core\\My_Model.php on line 111 致命错误:在第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
    }
}

what's the reason behind? 背后的原因是什么?

EDIT 编辑

this is my material model it has table name and all table fields 这是我的材料模型,它具有表名称和所有表字段

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;
}

this is my MY_Model it has table name and get method to get all result 这是我的MY_Model,它具有表名和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;
}

Finally i have solved my problem by simply calling mysql query instead store procedure 最后,我通过简单地调用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
    }
}

but i am confused my that error acure when calling store procedure instead query 但是我很困惑我在调用存储过程而不是查询时会出错

class Report extends MY_Controller{
    public function item_ladger()
    {
        $this->load->model("Material_Model"); # loding Model
        $inventory = $this->Material_Model->get_data(); # caling Model to do my code

        if ($inventory['cup']) { # retrivig data from retund array
            echo "I never ate Cup Cakes";
        }

    }
}

In Model 在模型中

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
}

Codeigniter SELECT Codeigniter SELECT

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:在(CodeIgniter)中的非对象上调用成员函数query() - Fatal error: Call to a member function query() on a non-object in (CodeIgniter) codeigniter致命错误在非对象上调用成员函数cookie() - codeigniter fatal error Call to a member function cookie() on a non-object 致命错误:在非对象,代码点火器控制器上调用成员函数 - Fatal error: Call to a member function, on a non-object, codeigniter controller Codeigniter 致命错误:调用非对象上的成员函数 query() - Codeigniter Fatal error: Call to a member function query() on a non-object Codeigniter 应用程序返回“致命错误:在实时而非本地调用非对象 in”上的成员函数 result() - Codeigniter App Returns `Fatal error: Call to a member function result() on a non-object in` on live but not local CodeIgniter随机PHP致命错误:在... mysqli_driver.php中的非对象上调用成员函数。 - CodeIgniter Random PHP Fatal error: Call to a member function … on a non-object in … mysqli_driver.php CodeIgniter致命错误:调用非对象上的成员函数display_clients() - CodeIgniter fatal error: Call to a member function display_clients() on a non-object Codeigniter / Postgresql:致命错误:在非对象上调用成员函数num_rows() - Codeigniter/Postgresql: Fatal error: Call to a member function num_rows() on a non-object Codeigniter-致命错误:在非对象上调用成员函数get_news() - Codeigniter- Fatal error: Call to a member function get_news() on a non-object Codeigniter:致命错误:在非对象上调用成员函数num_rows() - Codeigniter : Fatal error: Call to a member function num_rows() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM