|
本帖最后由 蔚蓝 于 2014-4-12 20:41 编辑
教程http://codeigniter.org.cn/user_guide/tutorial/news_section.html
里面我试了一下 点击某一个新闻标题的时候转到新闻详情里面 跑不起来,不知道各位有没有试过,报错如下
A PHP Error was encounteredSeverity: Notice
Message: Undefined index: title
Filename: controllers/news.php
Line Number: 25
CodeIgniter 2 TutorialA PHP Error was encounteredSeverity: Notice
Message: Undefined index: title
Filename: news/view.php
Line Number: 2
A PHP Error was encounteredSeverity: Notice
Message: Undefined index: text
Filename: news/view.php
Line Number: 3
这个意思是说找不到列title和text,教程里面的代码这样写的
public function view($slug){
$data['news_item'] = $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');
}
发现$data['news_item'] = $this->news_model->get_news($slug);这句话返回的是二维数组,不是一位数组,所以$data['title'] = $data['news_item']['title'];这句报错了啊 , 应该是$data['title'] = $data['news_item'][0]['title'];这样写才对的,对应的视图里面一样也要修改一下才可以,教程里面是这样写的
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
?>
一样的错误,应该这样写
<?php
echo '<h2>'.$news_item[0]['title'].'</h2>';
echo $news_item[0]['text'];
?>
各位大神有没有遇到类似问题?
|
|