I’ve been looking at CodeIgniter this week, a PHP MVC framework built by the ExpressionEngine folks at EllisLab. And while I usually find frameworks constraining, CodeIgniter avoids most of the common chafing with a simple, grounded approach.
The library runs under any recent version of PHP (4.x, 5.x), installs in a single directory in the web root of your project, and has minimal dependencies. It provides a simple MVC framework, a large set of helper classes, and a good amount of documentation. The site has two video tutorials, which are enough to get you started.
The pitch
You want a framework that does not require you to use the command line.
You can safely ignore the marketing fluff. The ‘no-command-line’ claim turned me off at first, as there’s nothing wrong with a framework that relies on a command line (and avoiding it misses out on some powerful tools). After working with the kit for a few weeks, it’s obvious that they’re talking about how it’s laid out in a simple, obvious way, and how it doesn’t require running helper scripts for scaffolding and initial setup. It’s not anti-command line at all, rather it’s just not as intensive as Rails (for example).
The good
CodeIgniter does MVC using a set of simple base classes, routing pages requests in an obvious way through controller class members, who in turn expose views. The kit also provides a modest library of utility classes that fit the MVC abstraction, a simple ActiveRecord DB class, and a set of helper modules that provide common web site functions. I found the approach immediately obvious, and it worked well in all of my test code.
An example:
class Bugs extends Controller {
function index() {}
function comments() {}
}
The comments() member is called on the /bugs/comments/ URI, which then can set up queries and calls to display the appropriate view.
The library code is clean and clearly documented. I’m impressed by the layout of the kit, which makes it easy to work with from nearly any tool set. The ActiveRecord implementation hasn’t gotten in my way yet, but I haven’t built anything complex enough to properly test it. Performance is better than the larger PHP frameworks, as you can easily tailor what is loaded for a given application.
The bad
I’m disappointed that there is no access to tagged Subversion releases of the framework, as it’s a simple way to keep in sync. There also doesn’t seem to be much consideration for AJAX, though nothing about the design prevents it. And, I’m still not sold on abstracting the already-great abstraction of SQL, though many people prefer it.
Here’s an example of an ActiveRecord query:
$this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20);
$query = $this->db->get();
Luckily CodeIgniter doesn’t require the use of ActiveRecord, though I was surprised to find that the abstraction worked well for the simple problems. The wrapped approach may get in the way with the harder problems, though, and I’m curious to see if mixing ActiveRecord and plain-old SQL is workable.
I couldn’t find many larger sites or projects using the framework, but I have seen many good uses of their ExpressionEngine. The lack of users may harm the kit long term, and it certainly hampers the amount of anecdotal documentation available online. But popularity isn’t the only measure in a tool.
A “good enough” framework
I like CodeIgniter enough to keep using it. It’s clean and simple, which is a feat in itself. I am wary of its lack of popularity, but it’s clear that the company behind it knows what they’re doing. And while it’s not as hip as Rails, it’s clearly capable and mature enough for production.