Coding - PHP

CodeIgniter 101

Want to save time on PHP development? In this article, I’ll cover the CodeIgniter framework and will provide you with a list of additional resources.

CodeIgniter (CI) is similar to Bootstrap, it’s an open-source toolkit that offers pre-existing code files for rapid development, but CodeIgniter is for PHP. The CI framework is based on the software architecture known as MVC which stands for Model-View-Controller. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

Here’s how EllisLab, CodeIgniter’s initial developer defines it:

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.

The beauty of CodeIgniter is that it is light and fast when compared to other PHP frameworks, and it’s very well documented with detailed comments (see comment code below!)

<!--?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { 	/** 	 * Index Page for this controller. 	 * 	 * Maps to the following URL 	 * 	 *	- or - 	 * 	 *	- or - 	 * Since this controller is set as the default controller in 	 * config/routes.php, it's displayed at 	 * 	 * So any other public methods not prefixed with an underscore will 	 * map to /index.php/welcome/ 	 * @see 	 */ 	public function index() 	{ 		$this--->load->view('welcome_message');

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

To get started, you can download the CodeIgniter framework here. Extract the contents and place them into your root folder.

CodeIgniter Sample Files

Expanding upon the Model-View-Controller software architecture, we can further define these categories:

  • The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
  • The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “page”.
  • The Controller serves as an intermediary between the Model, the View, and any other resources needed to generate a web page.

Although CodeIgniter can support query strings, the URLs in CodeIgniter are meant to be human-friendly. So, instead of this: you get this:
The segments in the URL, in following with the Model-View-Controller approach, usually represent:

  1. The first segment represents the controller class that should be invoked.
  2. The second segment represents the class function, or method, that should be called.
  3. The third, and any additional segments, represent the ID and any variables that will be passed to the controller.

Ok, now let’s get to the good part! Here’s what you get with CodeIgniter:

CodeIgniter Sample Folders

CodeIgniter Sample Folders

You get the application folder where you’ll mostly work in the views, models and controllers folders.  Don’t touch the system folder!

The controller is a class file that is named in a way that can be associated with a URL. The default controller included with CodeIgniter is welcome.php which is found here: /application/controllers/welcome.php. So the URL would then be

When a controller’s name matches the first segment of a URL, it will be loaded. Within this welcome.php file there’s a view. A view is a web page, or a page fragment (header, footer, sidebar).  You can have many views within one controller.

	public function index()

In the sample code above, the controller file welcome.php will load the welcome message contained in the view file welcome_message.php (this file is also a CodeIgniter default file which can be found here: /application/views/welcome_message.php).

Here’s some sample code from the welcome_message.php file:

<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">The page you are looking at is being generated dynamically by CodeIgniter.

If you would like to edit this page you'll find it located at:


The corresponding controller for this page is found at:


If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</div>

Going Deeper

You don’t need to work with models in CodeIgniter, you can build your application minimally using controllers and views. Models are PHP classes that are designed to work with information in your database. The user guide from CodeIgniter gives the following example: let’s say you use CodeIgniter to manage a blog. You might have a model class that contains functions to insert, update, and retrieve your blog data.

The files inside /application/config are also important. You will have to change the database.php file in order to connect to your database, autoload.php to automatically load classes from CI’s library (such as: encrypt.php, session.php); and config.php to specify the database’s configuration preferences.

In the /system/libraries folder you will find the sample classes that come with CI. You don’t want to edit these, but you can use several of them within your controller file. So let’s say you want to add pagination, you would then want to call pagination.php in your controller file.


You can create your own libraries and add them to your own CI framework.

Screen Shot 2014-04-23 at 3.18.17 PM.png

Using CodeIgniter will save you time as it is a well documented framework with resources/user guides and instructions available online. This is just one more of the web development tools to add to your knowledge base.

Additional Resources

About the author

Patricia is the Founder of Upwards Content, a fledgling content creation/management business. If you like my articles, follow me on Twitter!

Share this post

Leave a Comment

Subscribe To Our Newsletter