I was looking around for this problem a lot! But nothing realy helped to solve this issue.
I always get the following error: "Fatal error: Call to a member function query() on a non-object"
I have the following Controller:
<?php
class Station extends CI_Controller {
function __construct($params=array()) {
parent::__construct();
session_start();
$this->load->library('parser');
$this->load->helper(array('form', 'url'));
}
public function index() {
$this->tpl_data['location'] = $this->stationmodel->getLocations()->all;
$_SESSION['location'] = $this->tpl_data['location'];
$this->load->view('station', $this->tpl_data);
}
}
?>
And the following Model:
<?php
class StationModel extends CI_Model {
function __construct() {
parent::__construct();
}
public function getLocations() {
$query = $this->db->query("SELECT * FROM location WHERE City_IATA = 'MUC'");
var_dump($query);
// Just for test purposes!
foreach($query->result() as $row) {
echo $row->Location_Name_DE . '<br />';
}
}
}
?>
In my autoload.php I load the database module:
$autoload['libraries'] = array('database');
Also when I try to load the database modul directly in the controller I will get the same error.
My database.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '****';
$db['default']['database'] = 'comvel';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Anyone can help me out?
Thanks in advance!