I'm new to codeigniter, and I'm stuck trying to figure out what is going on in this line.
here is my controller
class Product extends CI_Controller{ function index(){ $this->load->model('product_model'); $data['products'] = $this->product_model->get_all_products(); $this->load->view('all_products', $data); } }
here is my model
class Product_model extends CI_Model { function get_all_products(){ $query = $this->db->get('products'); if($query->num_rows() > 0){ foreach($query->result() as $row){ $data[] = $row; } return $data; } } }
and here is my mistake
A PHP Error was encountered Severity: Notice Message: Undefined property: Product::$db Filename: core/Model.php Line Number: 50 Fatal error: Call to a member function get() on a non-object in /Users/matt/Sites/ci/application/models/product_model.php on line 9el.php on line 6
error in this line
$query = $this->db->get('products');
why this fails because the codeigniter documentation describes it this way ... I also have a product table
Trace source share