views:

372

answers:

2

Hello,

I've written a new model for my CodeIgniter framework. I'm trying to load the database from within the constructor function, but I'm getting the following error:

Severity: Notice
Message:  Undefined property: userdb::$load
Filename: models/userdb.php
Line Number: 7

Fatal error:  Call to a member function database() on a non-object in 
/var/www/abc/system/application/models/userdb.php on line 7

Here is my model:

<?php

class userdb extends Model {

    function __construct() {

        $this->load->database();

    }
?>

What am I doing wrong here?

Thank you.

+7  A: 

You're forgetting to call the parent constructor first. Something like:

<?php

class userdb extends Model {

function __construct() {

    parent::Model();

    $this->load->database();

}
?>
Jens Roland
My bad, checked the wrong answer.
thedp
+2  A: 

I'm not sure if it would cause a problem or not, but Model names are supposed to have the first letter capitalized. http://codeigniter.com/user_guide/general/models.html Jens is also correct that you need to call the parent constructor as well.

Rob Lund
That was my first thought as well - CodeIgniter naming conventions require capitalized class names. I was going to write that until I noticed the missing constructor call ;)
Jens Roland
`parent::Model();` did the trick. As for the Uppercase letter in the class/model name, I really hate it but I changed it to avoid possible errors. Thank you for your help.
thedp
How is this the best answer when it didn't even specified the correct answer? Jens below answered correctly.
Thorpe Obazee
I have to agree with Thorpe. This answer was helpful, but I'm a little disappointed that I didn't get the checkmark
Jens Roland