1.5. Revisiting the Opening Example

Now that you've got the basics of MVC down and understand how CodeIgniter differs from other PHP-based MVC frameworks, it's time to revisit the opening example. Instead of struggling with the original code, imagine that you had access to CodeIgniter and you were recoding it from scratch.

In the following sections, you see how you'd go about doing that. The examples provided in the next few pages don't stop long enough to explain how to install and configure CodeIgniter (that's Chapter 3) or talk about all the advanced features like caching, routing, and the extensive libraries. The assumption is that all that's been done for you, and that you have a properly working CodeIgniter environment. The goal is to show you, at high speed, how a CodeIgniter application might look and behave.

1.5.1. First Things First: The Model

Depending on your work style, you may be inclined to tackle the views or controller first, but a good place to start is the model. Why? Because the model serves as the data foundation for your entire web application. Many of the controller's functions will rely on the model, so it's a good idea to have those tools all ready to go.

All CodeIgniter models have the same initial structure:

<?php
class Page_model extends Model{

  function Page_model(){
    parent::Model();
  }
}
?>

Notice that the name of the model (in this case, Page_model) is both the name of the class and the name of the initializing function. This file is stored in the ...

Get Professional CodeIgniter® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.