我创建了CRUD操作,我的视图功能没有显示显示404错误页面的视图页面。
我的代码如下
Controller
public function view($slug = NULL)
{
$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('user/header', $data);
$this->load->view('news/view', $data);
$this->load->view('user/footer');
}
Model
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get_where('news', array('user_id' => $this->session->userdata('user_id')));
return $query->result_array(); // $query->result(); // returns object
}
$query = $this->db->get_where('news', array('slug' => $slug, 'user_id' => $this->session->userdata('user_id')));
return $query->row_array(); // $query->row(); // returns object
}
View
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];