Saturday, September 6, 2008

CodeIgniter: Model loading and non object error

I was playing around with CI today and created a user folder in the model folder. Inside the user folder I have a Loginmodel.php file with the Loginmodel php class inside. I load the model with $this->load->model('loginmodel'); but then when I want to call a method on the Loginmodel object I get the following.

Fatal error: Call to a member function user_login() on a non-object in /home/username/public_html/example.com/public/ci/application/controllers/user/login.php on line 20

To fix this I specified the object name upon load, and I used the class name.

$this->load->model('loginmodel','Loginmodel');

This fixed all the issues, however it should have worked the first way. Any idea why it didnt?

2 comments:

Ashish said...

rename the file login.php to loginmodel.php otherwise change the name of the class to Login in lieu of Loginmodel

Frank said...

The model is already been named loginmodel.php but I will double check the model class name now.

Thanks!
Frank