Welcome Guest, Not a member yet? Register   Sign In
New on CI
#1

[eluser]skunkio[/eluser]
Hi all,
I have started today reading the CI user guide and I find it very interesting.
I have executed the basic example within the Tutorial section but an error occurs and I’m not really getting why. Within the explained example (that I’m sure everybody have read already) you can start with CI modelling controllers, views, modules and some db stuff using news page as case study.
I don’t know why I receive a 404 error when I try to follow the example in order to read a single new. I have modified the routes file adding

Code:
$route['news/(:any)'] = 'news/view/$1';

I have modified my model with the follows

Code:
public function get_news($slug = FALSE)
    {
     if ($slug === FALSE)
     {
      $query = $this->db->get('news');
      return $query->result_array();
     }

     $query = $this->db->get_where('news', array('slug' => $slug));
     return $query->row_array();
    }

I have added the code below within my controller

Code:
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');
}

and, of course, I have created the view.php page Smile
It works properly when I have to add a new or read all of them but it's not working when I want to read a specific one.
What am I missing?

Thanks in advance Smile




Theme © iAndrew 2016 - Forum software by © MyBB