Resources

Get CodeIgniter
Download the CodeIgniter v.3.1.13 zip file: CodeIgniter-v3.1.13.zip
Download CodeIgniter from codeigniter.com/download Note: Use Version 3.1.13. You will see version 4 on the CodeIgniter site, but that is a work-in-progress, and the structure of the directories (and other details) will vary from the exercises.

What is CodeIgniter? CodeIgniter is a PHP framework based on the Model-View-Controller (MVC) design pattern. The MVC design pattern organizes code into modules, depending on the code's function.

  • Models deal with data, calculation and interfacing with the database.
  • Views deal with presentation, the user interface and the browser.
  • The Controller is somewhat like a "director", handling the sequence and flow of information.

The controller will call the model's functions for fetching data, then pass that data to the view, where it is used to compose the web page presented in the browser.

Working with CodeIgniter has a learning curve. It is PHP, but the way the code is structured, and the many specialized CodeIgniter functions make it challenging to use for the first time. However, the benefits CodeIgniter provides, (and the benefits of the MVC design pattern in general) make it well worth the investment of time and effort.

These benefits include:

  • Cleaner code. MVC makes it much easier to keep presentation code from being mixed with other types of PHP scripting.
  • An organized way to structure the project files. The database scripts are always going to be stored with the Models, and the HTML markup will always be with the Views, etc.
  • Distributed workload for teams. Database people can work on models, while the front-end developer can focus on the views.
  • Portable code. Configuration files make it very simple to move CodeIgniter projects from one server or database to another.
  • Routine tasks are handled behind the scenes. CodeIgniter handles libraries, helper files, databases, sessions, and much more in a behind-the-scenes manner. These processes are still available to you if you need them, but you don't generally need to look for them. You are free to focus on the functionality of your project.

And don't forget, as the CodeIgniter documentation repeatedly reminds you, it's just PHP. You can do it "your way", if that suits your purposes better.

How to best use CodeIgniter. The most important thing to learn about CodeIgniter at the start is the "layout", or structure of the directory system, and how the logical flow moves from Controller to Model (and back), and then to the View. This starts with the way Model and Views are loaded in the Controller, how data is requested and returned from the Model, and how data is passed to the View, and accessed there.

Once this basic schema is understood, it can be extended to AJAX calls, which originate in the browser, but follow a very similar track from Controller to Model and back, then back out to the browser/View.

CodeIgniter has many, many features that become more important as you gain experience. In particular, the way CodeIgniter abstracts working with the database is very important. But it is not necessary to learn these features at the start. CodeIgniter is extremely flexible with allowing you to use the PHP coding style you are most comfortable with. However, as you find a need for the more advanced features and functions, you will wonder why you did it any other way.