In the first tutorial there is an error that occurs in the news controller and view. The tutorial shows the following code in the controller:
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');
}The view file code is:
echo '<h2>'.$news['title'].'</h2><p>';<br />
echo $news['text'];That configuration produces an error. I was able to figure out that naming the $data array key as $data[‘news_item’] is what created the error. The table name in the database is “news”. When I changed the declaration to $data[‘news’] everything worked fine: Modified code in the controller:
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news']))
{
show_404();
}
$data['title'] = $data['news']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}Updated code in view file:
echo '<h2>'.$news['title'].'</h2><p>';<br />
echo $news['text'];Anyone else going through this tutorial experienced the same issue?