views:

38

answers:

3

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);
    }
}
?>
+1  A: 

I think this $this->load->model('Product_model'); will create a model with name Product_model and not product_model... PHP is case sensitive.

Ronaldo Junior
Thanks my friends. Both answers equally correct and helpful, I simply gave it to RJ for being first. And I have been staring at the caps thing but it just seemed to be not wrong, but it was.
Smandoli
+2  A: 

Just change:

$this->load->model('Product_model');

to:

$this->load->model('product_model');

It seems like the name passed to the loader references the file name.

Favio
+1  A: 

CI's model names are case sensitive, so "product_model" instead of "Product_model" will do the job. If you want to, you can set some sort of an alias, If I remember correctly, it goes something like

$this->load->model('product_model', 'Product_model');

that would have also worked.

EDIT: slight typo in the alias. fixed

Ygam
Thanks, I have seen ref to that, now I'll be able to make use of it.
Smandoli