Welcome Guest, Not a member yet? Register   Sign In
Tutorial error...?? (RESOLVED)
#1

[eluser]Matteo[/eluser]
From a new CI user...

I was following the tutorials and got the first part of the news page to work, but when I click on the "slug" entry to go to the second single-post page, I get CI's 404 error.

My model code is as follows:
Code:
<?php
class News_model extends CI_Model {

public function __construct() {

  $this->load->database();
}

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();
}
}
My View code (/views/news/index.php) is as follows:
Code:
<?php foreach ($news as $news_item): ?>

    <h2>&lt;?php echo $news_item['title'] ?&gt;</h2>
    <div id="main">
        &lt;?php echo $news_item['text'] ?&gt;
    </div>
    <p><a hre="news/&lt;?php echo $news_item['slug'] ?&gt;">View article</a></p>

&lt;?php endforeach ?&gt;
and my view code for the single page (/views/news/view.php) is as follows:
Code:
&lt;?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
My controller code is:
Code:
&lt;?php
class News extends CI_Controller {

  public function __construct()
  {
   parent::__construct();
   $this->load->model('news_model');
  }

  public function index()
  {
   $data['news'] = $this->news_model->get_news();
   $data['title'] = 'News archive';
  
   $this->load->view('templates/header', $data);
   $this->load->view('news/index', $data);
   $this->load->view('templates/footer');
  }

  public function view($slug)
  {
   $data['news'] = $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');
  }
}
Just for good measure, I have included my routes file as well...
Code:
*/

$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
//$route['404_override'] = '';
I would have posted the HTML, but the forum won't let me...


Messages In This Thread
Tutorial error...?? (RESOLVED) - by El Forum - 01-23-2012, 05:03 PM
Tutorial error...?? (RESOLVED) - by El Forum - 01-23-2012, 07:41 PM
Tutorial error...?? (RESOLVED) - by El Forum - 01-24-2012, 09:56 AM
Tutorial error...?? (RESOLVED) - by El Forum - 01-24-2012, 05:26 PM
Tutorial error...?? (RESOLVED) - by El Forum - 01-24-2012, 10:14 PM
Tutorial error...?? (RESOLVED) - by El Forum - 01-25-2012, 02:02 AM
Tutorial error...?? (RESOLVED) - by El Forum - 01-25-2012, 02:03 AM
Tutorial error...?? (RESOLVED) - by El Forum - 01-30-2012, 08:04 PM
Tutorial error...?? (RESOLVED) - by El Forum - 01-31-2012, 01:20 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-09-2012, 04:57 AM
Tutorial error...?? (RESOLVED) - by El Forum - 02-09-2012, 10:50 AM
Tutorial error...?? (RESOLVED) - by El Forum - 02-12-2012, 02:44 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-12-2012, 07:08 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-12-2012, 08:41 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-16-2012, 01:07 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-16-2012, 03:25 PM
Tutorial error...?? (RESOLVED) - by El Forum - 03-04-2012, 09:42 PM
Tutorial error...?? (RESOLVED) - by El Forum - 07-18-2012, 09:13 AM
Tutorial error...?? (RESOLVED) - by El Forum - 08-22-2012, 03:18 AM
Tutorial error...?? (RESOLVED) - by El Forum - 08-22-2012, 03:24 AM
Tutorial error...?? (RESOLVED) - by El Forum - 10-16-2012, 01:28 PM
Tutorial error...?? (RESOLVED) - by El Forum - 02-03-2013, 02:25 AM
Tutorial error...?? (RESOLVED) - by El Forum - 02-04-2013, 11:35 AM
Tutorial error...?? (RESOLVED) - by El Forum - 08-26-2014, 08:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB