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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办