[eluser]ignitian[/eluser]
MODEL FILE : \application\models\blog.php
Code:
class Blog extends Model
{
public $title = '';
public $content = '';
public $date = '';
function __construct()
{
parent::Model();
}
public function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
public function insert_entry()
{
$this->title = $this->input->post('title');
$this->content = $this->input->post('content');
$this->date = time();
$this->db->insert('entries', $this);
}
public function update_entry()
{
$this->title = $this->input->post('title');
$this->content = $this->input->post('content');
$this->date = time();
$this->db->update('entries', $this, array('id' => $this->input->post('id')));
}
}
CONTROLLER FILE : \application\controllers\welcome.php
Code:
class Welcome extends Controller
{
function __construct()
{
parent::Controller();
}
function index()
{
$this->template->set('template1');
$data = array('title'=>'Welcome','h1'=>'Intro');
$this->template->show($data);
}
function get_news()
{
$this->template->set('template2');
$data = array('title'=>'Welcome','content'=>$this->get_last_news());
$this->template->show($data);
}
function get_last_news()
{
$this->load->model('Blog'); // THIS IS NOT WORKING
$data['query'] = $this->Blog->get_last_ten_entries();
return $data['query'];
}
}
ERROR
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$Blog
Filename: controllers/welcome.php
Line Number: 29
Fatal error: Call to a member function get_last_ten_entries() on a non-object in C:\wamp\www\site1\application\controllers\welcome.php on line 29
A simple call that is not working. Database is autoload. Any tips ?