1

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);
    }
}
?>

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

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.
1

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.