dsk95913 2013-07-02 08:20
浏览 47

在codeigniter中在控制器中加载模型时出错:消息:未定义属性:Cart :: $ load

I am a beginner in codeigniter and currently I am working on a shopping cart, taking help from http://net.tutsplus.com/tutorials/php/how-to-build-a-shopping-cart-using-codeigniter-and-jquery/ tutorial. I am using codeigniter 2.1.3.

I am getting an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Cart::$load

Filename: controllers/cart.php
Line Number: 7

Fatal error: Call to a member function model() on a non-object in D:\xampp\htdocs\ci\application\controllers\cart.php on line 7

Can someone please tell me why it is not working?

The name of my controller is cart.php

<?php
class Cart extends CI_Controller {

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

    public function index()
    {
        $data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
        print_r($data['products']);
        //$data['content'] = 'cart/products'; // Select view to display
        //$this->load->view('index', $data); // Display the page
    }
}
?>

and my model is cart_model.php

<?php
class Cart_model extends CI_Model{
    //public function _construct(){
        //parent::_construct();
    //}

    public function retive_products(){
        $query = $this->db->get("products");
        return $query->result_array();
    }
}
/* End of file cart_model.php */  
/* Location: ./application/models/cart_model.php */
?>
  • 写回答

2条回答 默认 最新

  • drxnfdx798517235 2013-07-02 08:27
    关注

    Codeigniter 2.1.3 is intended to support PHP 5.2.4 and newer.

    Change the class constructor:

    <?php
      class Cart extends CI_Controller {
        public function __construct()
          {
             parent::__construct();
          }
    

    instead of

    public function cart()
        {
            parent::CI_Controller();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?