application\controllers\news.php on line 20语法错误
新手求教:按手册写“读取新闻条目”代码,出现语法错误Parse error: syntax error, unexpected T_PUBLIC in C:\mycx\Apache2\Ci\application\controllers\news.php on line 20,这一行代码是:public function index()
{
检查,不知道错误在哪,请高手赐教!
按手册写的代码如下: 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 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');
}
创建新闻条目时,输入http://localhost/index.php/news/后显示
A PHP Error was encountered
Severity: Notice
Message: Undefined property: News:db
Filename: core/Model.php
Line Number: 51
Fatal error: Call to a member function get() on a non-object in C:\mycx\Apache2\CodeIg\application\models\news_model.php on line 26
看看第19行是否漏了}或者;,并且检查一下class X extends CI_controller里面的代码是否正确。 本帖最后由 angusouyang 于 2014-7-15 15:10 编辑
应该是因为你这个方法没有放在 News 类里面 本帖最后由 sn01615 于 2017-4-10 02:48 编辑
语法错误 错误应该在这一行的上面 谢谢回答,但我从头做过了,有时又不是这个错误,现在出现在这样的的显示:
A PHP Error was encountered
Severity: Warning
Message: preg_match() : Compilation failed: missing ) at offset 5
Filename: core/Router.php
Line Number: 381
CodeIgniter 2 Tutorial
鍕ゅ伐鍔╁娆㈣繋浣�©2014 是不是没有引入news_mode模型。
重新做了,现在又能这样的错误A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$db
Filename: core/Model.php
Line Number: 51
Fatal error: Call to a member function get() on a non-object in C:\mycx\Apache2\CodeIg\application\models\news_model.php on line 26
页:
[1]
2