具体数据不会出现在codeigniter中

i am doing some practice on the codeigniter to retrieve the data from database and i am success to do this.but the problem arise when i want to fetch data of a specific field. to retrieve the specific value i am using the following URL on my local host:

localhost/codeigniter/index.php/news/view/city-news

where news is controller,view is method of controller and city-news is argument.

Here is my code of controller:

public function view($slug)
    {

        $data['news'] = $this->news_model->get_news($slug);//here i am getting the slug value.
                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');
    }

this method calls the method get_news($slug) of model news_model.here is the code of this method:

public function get_news($slug = FALSE)
   {

    if ($slug === FALSE)
    {
        $query = $this->db->get('news');
        return $query->result_array();
    }
    echo $slug;//here is i m also getting the slug value.
    $query = $this->db->get_where('news', array('slug' => $slug));//i think this is not working properly
    print_r($query->row_array());die;//now i am getting values here.   
    return $query->row_array();
   } 

but still my view shows "404 page not found". my view code is:

<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
?>

Now please tell me where i am going wrong.

查看全部
doudao1369
doudao1369
2012/08/24 11:42
  • codeigniter
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

5个回复