CodeIgniter -- unable to use an object
        Posted  
        
            by Smandoli
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Smandoli
        
        
        
        Published on 2010-05-17T03:55:18Z
        Indexed on 
            2010/05/17
            4:00 UTC
        
        
        Read the original article
        Hit count: 240
        
codeigniter
|php
THE SUMMARY:
When I call .../index.php/product, I receive:
Fatal error: Call to a member function get_prod_single() on a non-object in /var/www/sparts/main/controllers/product.php on line 16
The offending Line 16 is:
$data['pn_oem'] = $this->product_model->get_prod_single($product_id);
Looks like I don't know how to make this a working object. Can you help me?
THE CODE:
In my /Models folder I have product_model.php:
<?php
class Product_model extends Model {
    function Product_model()
    {
        parent::Model();
    }
    function get_prod_single($product_id)
    {
        //This will be a DB lookup ...
        return 'foo';  //stub to get going
    }   
}
?>
In my /controllers folder I have product.php:
<?php
class Product extends Controller {
    function Product()
    {
        parent::Controller();
    }
    function index()  {
      $this->load->model('Product_model');
      $product_id = 113; // will get this dynamically
      $data['product_id'] = $product_id;
      $data['pn_oem'] = $this->product_model->get_prod_single($product_id);
      $this->load->view('prod_single', $data);
    }
}
?>
© Stack Overflow or respective owner