我正在尝试CodeIgniter用户指南2.2.0版中的教程。我只是遵循粘贴的代码,但是却收到此错误消息。这里到底有什么问题?
Fatal error: Non-abstract method News_model::__construct() must contain
body in /var/www/leomel/application/models/news_model.php on line 3
源代码:
<?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');
}
}
该错误属于不同的类,News_model
而您已经显示了News
错误是自描述性的-您必须指定方法主体,除非它是抽象的。
您大概拥有:
public function __construct();
您必须具备什么:
public function __construct()
{
// method's body
}
我不小心在News_model类中的函数后放置了分号。解决了,谢谢!