CodeIgniter Forums
Undefined property Cart::$Cart_model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Undefined property Cart::$Cart_model (/showthread.php?tid=60998)



Undefined property Cart::$Cart_model - El Forum - 08-25-2014

[eluser]Unknown[/eluser]
Hello,

I've started to learn CI but I stuck at the beginning.. I following one tutorial where I must creat a Cart. What I've done is in controler/cart.php i have:
Code:
class Cart extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model('cart_model');
    }
    function index(){
        $data['cart'] = $this->Cart_model->retrieve_products();
        print_r($data['cart']);
    }

In models/cart_model.php
Code:
class Cart_model extends CI_Model {

    function retrieve_products(){
        $this->db->get('cart');
        return $this->result_array();
    }
}
The error that I get is
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Cart::$Cart_model

Filename: controllers/cart.php

Line Number: 8
Line number 8 -> $data['cart'] = $this->Cart_model->retrieve_products();

I have found some solutions in Google but none of them working in my case. Can someone explain what is wrong here?

Thank's in advance

p.s. Excuse my English... Still learn it Smile


Undefined property Cart::$Cart_model - El Forum - 08-25-2014

[eluser]InsiteFX[/eluser]
In your index method Cart_model should be lowercase cart_model


Undefined property Cart::$Cart_model - El Forum - 08-25-2014

[eluser]Unknown[/eluser]
Oh, this case sensitivity. Thank's for your help!