Pressure is nothing more than the shadow of great opportunity. - Michael Johnson

CodeIgnitor - MVC made simple

10 years, 10 months ago

I've spent the weekend trying out CodeIgnitor, a MVC framework for PHP. Reading their web site suggested CodeIgnitor would match my need for a framework which could take care of the basic, and usually extremely boring, building blocks inherent in a project of any size whilst at the same time avoiding the usually steep learning curve and bloated feature sets of other such frameworks.

CodeIgnitor seems to offer an easier introduction to MVC and I like the fact that it offers flexibility over whether to choose full blown MVC or a more reduced and, in some cases, optimal View-Controller configuration. In certain situations I feel the addition of "Models" is an abstraction level too far.

Setup was a breeze:

  1. Unzip the files into your web directory
  2. Add the following .htaccess file to handle the mod rewrite rules:
    1. RewriteEngine on
    2. RewriteRule ^$ /index.php [L]
    3. RewriteCond $1 !^(index\.php|images|css|javascript|robots\.txt)
    4. RewriteRule ^(.*)$ /index.php/$1 [L]

    It's worth pointing out that the documentation on the .htaccess rules misses out the second line (RewriteRule ^$ /index.php [L]) which is vital if you want CodeIgnitor to load the default view from the document root (/).

  3. Remove "index.php" from $config['index_page'] = "index.php"; in the system/application/config/config.php.

The CodeIgnitor site offers clear and concise documentation with simple code examples detailing every feature of the framework. There are also instructions on how to build on the default feature set. For me this is the greatest selling point and an area where many of the other frameworks fall short.

Another area where CodeIgnitor scores strong points is on its use of PHP as its main templating language. Whilst it does provides a simplistic templating class for those that might want it the author expresses his preference, and the obvious performance advantages, for using raw PHP.

Basic scaffolding functionality is provided but it should really only be considered for development purposes and it lacks the security features which would be required of a full blown site admin system. This is a shame and one weak area of CodeIgnitor particularly when compared to the fantastic interfaces offered by frameworks such as Django. That said it could probably be easily expanded or replaced using CodeIgnitor's plugin architecture.

This plugin architecture is made up of "helpers", "plugins" and "scripts". "Helpers" consist of simple sets of procedural functions which perform common tasks such as date formatting, string and cookie manipulation. The author suggests these form part of the core system but I can see situations where you might want to add to this default set. "Plugins" are used for more extensive functionality - the two examples included are a CAPTCHA and a calendar. The purpose of "scripts" is somewhat less clear although I get the impression the "scripts" directory is a place to store any other library code you might have that you wouldn't really consider to be a proper part of the CodeIgnitor framework.

Database manipulation is provided through a vendor independent database class. This provides support for the "Active Record Database" pattern which, in most cases, removes the need to write SQL queries. A separate pagination class provides the ability to page through database results sets as well as other data.

CodeIgnitor supports full page caching ensuring your application won't need to hit the database on each page request. Pages are cached for a specified number of seconds in temporary files written to the "system/cache" directory. If you find this feature doesn't work out of the box you may need to change the file permissions for the directory to allow the web server process (most likely Apache) to write to it. Fragment caching isn't currently supported but again could easily be added and will probably be something I'll look into implementing as a plugin.

There are many other cool features but a few that caught my eye included a class for manipulating images (via GD/GD2, NetPBM or ImageMagick), support for trackbacks and unit testing.

Generally CodeIgnitor seems to be really well thought out and the code is clean and easy to follow. When I get time I'll be looking to convert this site to use it. Given my experiences so far I doubt it will take me too long.


  • i plan to use codeignitor for my next project,

    i've learn some feature its has

    but, i'm still worry about their security handling,

    can u share your experience using codeignitor?


    dei - 19th February 2008 #

  • why not just upgrade to the new expressionEngine when it comes out. I don't see the need to use codeIgnitor for a blog except when you want to expand upon the features of expressionEngine. The newest version will be built from codeIgnitor.

    jim - 21st March 2008 #

  • I am using the latest version of Codeignitor currently for a big community site. I can tell you that Fragment caching now is a part of the basic codeignitor package, also there are a lot of plug ins that are more advanced and free to download from a large number of codeignitor fan sites.

    I can really advise this framework. it has great support and its very light.

    Dennis van Schaik - 29th October 2008 #

  • This is correct htaccess code:

    RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L]

    Jankit - 8th April 2010 #

Help make this post better

Notes: Standard BBCode for links, bold, italic and code are supported. rel="nofollow" is added to all links. Your email address will never be displayed on the site.

Back to index