Static pages

Note: This tutorial assumes you’ve downloaded CodeIgniter and installed the framework in your development environment.

The first thing you’re going to do is set up a controller to handle static pages. A controller is simply a class that helps delegate work. It is the glue of your web application.

For example, when a call is made to:

We might imagine that there is a controller named “news”. The method being called on news would be “latest”. The news method’s job could be to grab 10 news items, and render them on the page. Very often in MVC, you’ll see URL patterns that match:

As URL schemes become more complex, this may change. But for now, this is all we will need to know.

Create a file at application/controllers/Pages.php with the following code.

<?php
class Pages extends CI_Controller {

        public function view($page = 'home')
        {
        }
}

You have created a class named Pages, with a view method that accepts one argument named $page. The Pages class is extending the CI_Controller class. This means that the new pages class can access the methods and variables defined in the CI_Controller class (system/core/Controller.php).

The controller is what will become the center of every request to your web application. In very te