views:

65

answers:

5

I'm loading a model for my CodeIgniter based website, but it keeps giving an error:

"Fatal error: Call to a member function on a non-object in /nfs/c02/h05/mnt/30796/domains/planetchustar.com/html/arguit/system/application/controllers/home.php on line 8"

Here's the part of code its referencing:

function index()
{
        $this->load->model('posts');    //error here
        $result = $this->Posts->get_all_topics();
}

The model is called "Posts" and its filename is "posts.php".

EDIT: I found out one of my problems, which was that I wasn't loading to database before I tried to use its functions, so I fixed that, but now its saying:

A Database Error Occurred
Unable to connect to your database server using the provided settings.

But I'm certain the connection info I saved in the database.php file is accurate (got from the phpmyadin website).

+1  A: 

Is 'posts' in a subdirectory? If so then you need to reference the subdirectory during load.

If it's not that then here is a post which may help.

Arthur Frankel
Its not in a sub directory.
chustar
A: 

I agree with @arthur. Make sure you haven't tried to embed a controller within another controller.

musoNic80
A: 

It's a case sensitivity error....

use it like so:

function index()
{
        $this->load->model('posts');    //error here
        $result = $this->posts->get_all_topics();//<-- Notice "posts" and not "Posts"
}
pǝlɐɥʞ
According to the usermanual, they said to name the file in lowercase, and name the class in Uppercase, but I'll change it and see.
chustar
According to the usermanual, they said to name the file in lowercase, and name the class in Uppercase. And changing it doesn't work.
chustar
follow the user manual... leave the file lower case and the class upper case, But when you call the class like the code above... use lower case.... let me know if that works
pǝlɐɥʞ
A: 

This means that $this->load is not an object reference (most likely null). Why maybe easy to determine once you know this.

Don
I think $this->Posts is not an object reference...
pǝlɐɥʞ
A: 

The codeigniter user guide is a little difficult to understand in this case. ONLY the file name should be lower case, the 'load' and the call ($this->Posts->etc()) should match the declaration in the model file.

It's is definitely a case sensitivity issue.

Zack