Hello.
I’ve made a class it’s being loaded and everything is fine with that.
Unfortunately when I want to get access to database PHP generates me fallowing error:
Fatal error: Call to a member function query() on a non-object in D:\WWW\CodeIgniter\system\application\controllers\news.php on line 8
File looks like that:
<?php
class News extends Controller {
function index()
{
$cnt='';
$this->lang = $this->lang->user_lang;
$this->load->database();
$res = $this->db->query('SELECT * FROM `news` WHERE lang=\''.$this->lang.'\' ORDER BY n_timestamp');
if($res->num_rows() > 0)
{
foreach($res->result_array() as $row)
{
$cnt = '<div id="news">
<div class="title">'.$row['n_title'].'</div>
<div class="date">'.date('H:i d.m.Y', strtotime($row['n_timestamp'])).'</div>
<div class="content">'.nl2br($row['n_content']).'</div>
</div>';
}
}
$vars = array('lang' => $this->lang, 'title' => $this->get_title(), 'content' => $cnt);
$this->page->set_vars($vars);
$this->page->show();
}
function get_title()
{
$titles['pl'] = 'Nowosci';
$titles['en'] = 'News';
return $titles[$this->lang];
}
}
?>
I’ve figure out that the problem is in Loader.
It doesn’t returns me anything and I don’t know why but when it’s called by Session class everything is fine. What should I do ?
edit>
Ok now i know why.
Library classes can’t extend controller.
Then how to use for example view in my Lib class ?
