Welcome Guest, Not a member yet? Register   Sign In
Loading Database Class In Model Constructor
#1

[eluser]Lane[/eluser]
I tried to add
Code:
$this->load->database();
to my class constructor within my model and for some reason, it does not seem to work. I am fairly new to CI, so it's likely I'm overlooking something. At any rate, I am using CI Reactor 2.0.2, PHP 5.3.3, connecting to a MySQL database. I have the db connection values in my database config file and I know it is working because when I add the same line of code to each function in my model, I get query results. It may be worth mentioning that I'm using the Active Records method of formulating and executing queries.

Here's the constructor declaration and error message when I add the call in my constructor rather than in each function:

Code:
function __constructor()
    {
        parent::__constructor();
        
        $this->load->database();
    }

Error Message:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Forgot_pw::$db

Filename: core/Model.php

Line Number: 50

Fatal error: Call to a member function where() on a non-object in C:\localhost\www\bn\application\models\forgotpw_model.php on line 18

Am I missing anything?
#2

[eluser]theprodigy[/eluser]
change
Code:
function __constructor()
    {
        parent::__constructor();
        
        $this->load->database();
    }
to
Code:
function __construct()
    {
        parent::__construct();
        
        $this->load->database();
    }
#3

[eluser]Lane[/eluser]
Wow, talk about a rookie mistake. Thanks for the tip! That solved it.




Theme © iAndrew 2016 - Forum software by © MyBB