douyun1852 2012-07-03 19:24
浏览 39
已采纳

错误调用Codeigniter控制器中涉嫌非对象的成员函数

I get the error

Fatal error: Call to a member function retrieve_products() on a non-object

The controller is:

<?php   
class Cart extends CI_Controller { // Our Cart class extends the Controller class  

   public function _construct()  
   {  
       parent::_construct(); // We define the the Controller class is the parent.  
       $this->load->model('Cart_model'); // Load our cart model for our entire class  
   }

   function index()  
   {  
      $data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products  
   }
}

The model is:

<?php   
class Cart_model extends CI_Model {

    function retrieve_products(){  
        $query = $this->db->get('products'); // Select the table products  
        return $query->result_array(); // Return the results in a array.
    }             
}
  • 写回答

3条回答 默认 最新

  • dqdt45183 2012-07-03 21:10
    关注

    I want to say that your call

    $data['products'] = $this->cart_model->retrieve_products();
    

    Should be:

    $data['products'] = $this->Cart_model->retrieve_products();
    

    Ie: uppercase "C" in cart_model

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击