Welcome Guest, Not a member yet? Register   Sign In
404 Error On News Tutorial
#1

Hi Everyone, I am pretty much new to Codeigniter and am working through the news tutorial on the Codeigniter website. I keep getting a 404 error when accessing index.php/news. Specifically, I get the following error:

Quote:load->model('news_model'); $this->load->helper('url_helper'); } public function index() { $data['news'] = $this->news_model->get_news(); $data['title'] = 'News archive'; $this->load->view('templates/header', $data); $this->load->view('templates/footer'); $this->load->view('news/index', $data); } 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('templates/header', $data); $this->load->view('news/view', $data); $this->load->view('templates/footer'); } }

404 Page Not Found
The page you requested was not found.

Below is all of my code. Does anyone have any thoughts? I appreciate any help.

Thanks!

News_model.php (Model)
PHP 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();
    }


News.php (controller)
PHP Code:
<?
class News extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        $this->load->model('news_model');
        $this->load->helper('url_helper');
    }
    
    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 = 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('templates/header', $data);
        $this->load->view('news/view', $data);
        $this->load->view('templates/footer');
    }


index.php (View)
PHP Code:
<h2><?php echo $title?></h2>

<?php foreach ($news as $news_item): ?>
    
    <h3><?php echo $news_item['title']; ?></h3>
    <div class="main">
        <?php echo $news_item['text']; ?>
    </div>
    <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View
    
<?php endforeach; ?>

view.php (View)
PHP Code:
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo 
$news_item['text']; 

routes.php
PHP Code:
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view'
Reply


Messages In This Thread
404 Error On News Tutorial - by mpar612 - 11-20-2015, 07:11 PM
RE: 404 Error On News Tutorial - by JayAdra - 11-20-2015, 08:55 PM
RE: 404 Error On News Tutorial - by mpar612 - 11-21-2015, 11:22 AM
RE: 404 Error On News Tutorial - by mpar612 - 11-23-2015, 10:47 AM
RE: 404 Error On News Tutorial - by Martin7483 - 11-23-2015, 11:21 AM
RE: 404 Error On News Tutorial - by mpar612 - 11-23-2015, 11:26 AM
RE: 404 Error On News Tutorial - by Martin7483 - 11-23-2015, 12:24 PM
RE: 404 Error On News Tutorial - by rohit176 - 11-24-2015, 08:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB