i am trying the tutorial in CodeIgniter User Guide Version 2.2.0. i just followed the code pasted but i got this error message. what is really wrong here?
Fatal error: Non-abstract method News_model::__construct() must contain
body in /var/www/leomel/application/models/news_model.php on line 3
the source code:
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
}
The error belongs to a different class News_model
whereas you've shown the code from News
And the error is self descriptive - you must specify a method body unless it's abstract.
What you presumably have:
public function __construct();
what you must have:
public function __construct()
{
// method's body
}
i accidentally put a semicolon after the function inside the News_model class. solved thank you!