Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Routing-404 error[SOLVED]
#1

[eluser]Unknown[/eluser]
Following along with the CI site News Tutorial

Tutorial


I'm only doing the news section so I changed the default controller to 'news'

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

Now a 404 error is generated from the 'View article' anchors. Changing the default to:


Code:
$route['default_controller'] = 'welcome';

creates the correct path. How should I change the router to use news?

No custom config, or .htaccess used.

From config.php:

Code:
$config['base_url'] = 'http://frameworks:8888/ci_site_tut/';
$config['index_page'] = 'index.php';

News Controller:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
    /**
    *
    */
    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_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');
     }
    
     public function create()
     {
      $this->load->helper('form');
      $this->load->library('form_validation');
      
      $data['title'] = 'Create A News Item';
      
      $this->form_validation->set_rules('title', 'Title', 'required');
      $this->form_validation->set_rules('text', 'Text', 'required');
      
      if ($this->form_validation->run() === FALSE)
      {
        $this->load->view('templates/header', $data);
              $this->load->view('news/create');
        $this->load->view('templates/footer');
      } else {
      
      
       $this->news_model->set_news();
       $this->load->view('news/success');
            
      }
      
      
      
     }
    
    }




Theme © iAndrew 2016 - Forum software by © MyBB