Welcome Guest, Not a member yet? Register   Sign In
Problem loading a model
#1

[eluser]Emass[/eluser]
Hello.
First, I hope I posted this in the right forum. If not I hope a moderator would move this where it belongs.

I'm facing a problem with loading the models. I think it is because I'm including classes by including them instead of CI's way of loading them through MY_classes. I try to do it this way because I think this way is much more organized. Working perfect except for loading models. Let me just show you an example. This code is inside the backcontroller, which is extending the controller which defines the pages as it's supposed to in CI. In this class I'm trying to load a model like this.

$this->load->model('login_model');
$this->login_model->updateUser($this->sleutel, $this->getLogin(), $this->getTimestmp());

The model looks like this:
<?php
class Login_model extends Model {

function Login_model() {
parent::Model();
}

function updateUser($sleutel, $login, $timestmp) {
$q = $this->db->query('SELECT * FROM `activity` WHERE sleutel = \'' . $sleutel . '\' LIMIT 1');
if($q->num_rows() > 0) {

//update
//$q = $this->db->query('UPDATE `activity` SET `login` = \'' . $login . '\', ');
} else {
//insert

}
var_dump('test');
}
}
?>

In this example I get the following fatal error:
Fatal error: Call to a member function test() on a non-object

It seems it's just not loading the model, even though I defined it in the backcontroller. So I thought I'd auto load the 'login_model' model from the autoload.php to see either it loads then, and with success, except I get the var_dump('test') twice, and I don't want to run my queries twice. Also when I take the $this->load->model('login_model'); out, it will still load it twice.
Anyone has any idea?
#2

[eluser]flaky[/eluser]
Code:
function updateUser($sleutel, $login, $timestmp) {
      $q = $this->db->query(‘SELECT * FROM `activity` WHERE sleutel = \’’ . $sleutel . ‘\’ LIMIT 1’);
      if($q->num_rows() > 0) {

        //update
        //$q = $this->db->query(‘UPDATE `activity` SET `login` = \’’ . $login . ‘\’, ‘);
      } else {
        //insert

      }
      //var_dump(‘test’); -- this here is the culprit
  }
}
#3

[eluser]Emass[/eluser]
The var_dump is inside the function updateUser so it should not give any problems. Or are models not capable of handling any var_dumps? The problem still stands without the var_dump aswell.
#4

[eluser]flaky[/eluser]
Models are capable of handling var_dumps, it's php code.
var_dump is expecting the variable test which doesn't exist in your model. That's why is the error appearing
#5

[eluser]Emass[/eluser]
No it's not, test is between '', so it's just printing plain text and not a variable.
#6

[eluser]danmontgomery[/eluser]
The error is for a section of code that you haven't pasted, in the code you're not calling test() anywhere. Give us the line that the error is on.




Theme © iAndrew 2016 - Forum software by © MyBB