• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fatal error: Call to a member function on a non-object

#1
[eluser]Ornis[/eluser]
I got stuck with an error: Fatal error: Call to a member function on a non-object in / ... application/models/zug_model.php on line 15

I load the model in the controller and call the function getSimple() :
<?php

class Vogelkarte extends Controller {

function Vogelkarte()
{
parent::Controller();
$this->css = $this->config->item('css');
$this->js = $this->config->item('js');
$this->load->model(array('Zug_model'));
}

function get_it() {
$data['artenauswahl'] = $this->Zug_model->getSimple('artenliste',
array('id','art_de'));
var_dump($data['artenauswahl']);
}
?>

The Model looks like this
<?php
class Zug_model extends Model {

/**
* Konstruktor
*/
function Zug_model() {
parent::Model();
}


function getSimple($table = '',
$fields = array()
) {
$this->db->from($table);
$this->db->select($fields);
return $this->db->get();
}
}
?>
Why do I loose the $this-db object?

I'm currently working with php 4.4.9. Thanks.

#2
[eluser]Maglok[/eluser]
Are you autoloading the database library?

#3
[eluser]Ornis[/eluser]
No

#4
[eluser]Maglok[/eluser]
Codeigniter does not auto load the database class cause not all apps need it. Basically it is telling you that it doesn't know what $this->db is, because you have not loaded the class. Either autoload it, or load it manually and it should fix itself. Smile

#5
[eluser]Ornis[/eluser]
Thanks! Solved, this was a trivial mistake. Sorry.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.