Hello, this is php in codeigniter. I have posted the same topic in codeigniter discussion forum, but I get a really long time to get a reply and some times do not get a reply at all. So may be if there are some codeigniter experts in this forum might be great. :).



class Pages extends CI_Controller {

public function create() 

 $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);



<h2>Create a news item</h2>

<?php echo validation_errors(); ?>

<?php echo form_open('news/create') ?>

 <label for="title">Title</label>
 <input type="input" name="title" /><br />

 <label for="text">Text</label>
 <textarea name="text"></textarea><br />

 <input type="submit" name="submit" value="Create news item" />


I point the url to: http://localhost/News/index.php/pages/create

This error appears:

404 Page Not Found

The page you requested was not found.

Why is it?

4 Years
Discussion Span
Last Post by paulkd

Yes, News is a rename from Codeigniter folder.



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

Edited by davy_yg


Yes, News is a rename from Codeigniter folder.

It is not clear to me. So you have a setup similar to this:


Correct? Be aware that News and news are different paths for the system. So if the name of the directory is all lower case your link will be:


Edited by cereal


If this is the route you expect to catch, I think it should be changed

$route['(:any)'] = 'pages/view/$1';


$route['pages/(:any)'] = 'pages/$1';


After having my eyes refreshed from looking at too many codes, I just noticed that your controller is missing lots of stuffs. For example, the contructor is missing. There should be a constructor here if you want to initialize the news_model and use its method called set_news().

Something like this

public function __construct()

because your original codes has this


and even this, you have pointing into the view/news directory


so, if your view files for the pages controller is located in the views/pages, then you will have to adjust everything including the routes.php .

It is also recommended to have a model class for your application. It can be called as pages_model.php or news_model the choice is yours. However, I highly recommend for you use the pages_model.php, because this will eliminate some the potential naming collision in the future.

Edited by veedeoo: info added


Hello, thanks. Now, the program works. I begin to understand the concept of routing.

What does this means:

    $this->load->view('templates/header', $data);

Can you load 3 php pages at the same time ? Or does it mean that it loads them in vertical order ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.