Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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"
}

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top