Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:49:16+00:00 2026-05-27T22:49:16+00:00

Following along with the CI News Tutorial I’m only doing the news section so

  • 0

Following along with the CI News Tutorial

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

$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:

 $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:

$config['base_url'] = 'http://frameworks:8888/ci_site_tut/';

$config['index_page'] = 'index.php';

News Controller:

<?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');

        }



    }

}

SOLUTION:

Autoload URL Helper:

$autoload['helper'] = array('url');

Updated routes:

$route['default_controller'] = 'news';
$route['404_override'] = 'errors/page_missing';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';

Updated URL in views/news/index.php:

<p><a href="<?php echo site_url('news/' . $news_item['slug']); ?>">View Article</a></p>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:49:16+00:00Added an answer on May 27, 2026 at 10:49 pm

    It doesn’t look like you are setting $new_item[‘slug’] anywhere in your view method. do a 'print_r($data['news_item']) in your view method just before you load your views to see if you actually are setting the slug.

    if you’re sure you are, make sure the url helper is autoloaded and try using this for your url in your view.

    <a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting started with Play 2.0 by following along with the tutorial. I'm hitting
I'm trying to a create an update statement along the following lines: TABLE car:
I'm following along the Rails for Zombies tutorial trying to get the gist of
I'm following along a tutorial (Ruby) that uses a regex to remove all html
I've been following along with this excellent asio tutorial , but have got confused
I'm fairly new to python and following along with part 4 of the tutorial
I am following along the Ruby on Rails Tutorial and have gotten somewhat confused
So I'm following along with this tutorial , and I'm stuck. In Eclipse, I'm
I was reading the Rails Tutorial and following along like a good drone installing
I am just following along the spring tutorial ( http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html ) I downloaded this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.