CodeIgniter Forums
Fatal error: Call to a member function on a non-object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Fatal error: Call to a member function on a non-object (/showthread.php?tid=28556)



Fatal error: Call to a member function on a non-object - El Forum - 03-15-2010

[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.


Fatal error: Call to a member function on a non-object - El Forum - 03-15-2010

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


Fatal error: Call to a member function on a non-object - El Forum - 03-15-2010

[eluser]Ornis[/eluser]
No


Fatal error: Call to a member function on a non-object - El Forum - 03-15-2010

[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


Fatal error: Call to a member function on a non-object - El Forum - 03-16-2010

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