µreview topic: CodeIgniter MVC Framework for PHP -- Now Scores (9/10)
Micro-review: CodeIgniter PHP framework (7/10); needs more OO & hooks, less PHP4. Very customizable, fast. Works well w/ Doctrine ORM.
About a month ago I tweeted a quick µreview about CI, and now I'm pleased to say that after another continuous month with the framework I'm revising the score to 9 out of 10.
I've been using the CI framework extensively for the past year, but tracking its progress for about two. A friend of mine and I are putting the finishing touches on a SaaS system built with CI, and it has proven invaluable for getting code written, tested and documented quickly, anything you find in my µcons list are purely nice-to-haves.
pros:
Excellent SpeedCodeIgniter really is quite fast. I've yet to benchmark it, but I plan to once our code hits its first release milestone. In testing with caching disabled and heavy database access, pages still render in the .03 to .09 second range (according to CI's internal Benchmark class) -- this is on a Quad Core machine, Apache 2.2.11 and PHP 5.2.6 with eAccelerator 0.9.5.3.
Once I have a better set of pages (light and heavy) I'll benchmark throughput under varying conditions -- client load, caching (CI and DB)
Pretzel-like Flexibility
CI allows inheritance of the core classes, such as built-in libraries or the Controller class itself, which simplifies managing complex core tweaks.
The built-in support for adding your own "helpers" -- related sets of functions included at runtime also helps to keep shared utility code organized.
The Hooks system provides a very valuable ability to run code at various points in your application's lifecycle, which reduces (or eliminates) the amount of tweaking you might need to do to the core.
Think modification of incoming URLs, data preprocessing, caching, etc. See:
CI Hooks for details on their hooking process.
Powerful Built-In Libraries and Helpers
Some of the libraries that I've found particularly useful include:
- Form Validation (Combined with jQuery validation this makes life with many dozens of forms that much more bearable)
- Calendaring Class (HTML Calendar generator -- has full templating support)
- Table Class (Self-explanatory -- the make_columns() method is my good friend now.)
I won't go into detail on the helpers, a quick run through the
CI User Guide will give you a fast overview of all their built-ins.
Plays nice with Doctrine
We don't use CI's built-in database abstraction layer (although we tried it), but integrating Doctrine into CodeIgniter was mostly painless.
Security
Built-in XSS filter (which can be enabled globally, or preferably called as you need it), scrubbing of globals to help avoid security issues on servers with register_globals = on. You do have register_globals off, don't you?
Auto-Loading (use caution)
Support for automatically loading libraries/helpers globally is built-in, but be judicious about what you autoload -- especially if you're writing a lot of AJAX -- you likely don't need all the overhead of extra libraries/helpers being loaded on every request. But if you really do need something everywhere, you've got it.
Documentation
CodeIgniter's User Guide is absolutely fantastic. Installation, configuration, complete reference for every library, helper and method of extending the core is included. This made getting started with CI that much faster.
Community
The forums on CodeIgniter.com are chock full of additional libraries, helpers, and helpful developers -- if you run into a snag, a quick trip there often provides fast resolution. (Indeed, our need to integrate Doctrine was a forum issue someone else had previously discussed -- and solved.)
cons:
Since the source code of CI is relatively tidy, nothing in this list was a show-stopper for us since modifying the core was easy.
Not fully OO
This was done to maintain PHP4 support -- so you're dealing with a lot of floating functions in included files. However for a large number of developers this is good since so many shared hosts still only support PHP4.
Inconsistent helper arguments
Sometimes the parameters you'll use to send class, id or other attributes along is called $attributes, sometimes it's $extra. It would be nice to see that standardized across all helpers.
Some unsual decisions
For instance: the anchor helper prepends the entire protocol/host to every href that doesn't have http: in it. (Seems that should be configurable behavior)
Flat Controller Loading
There's no built-in mechanism for organizing controllers into subdirectories -- when you have as many components to an application as we do, organization of the code is of utmost importance. CI should allow more than a single level of directory organization for controllers. (We modified the core to provide a limited version of this functionality.)
AJAX/partials support
It would be handy to have something like render_partial ala RoR and built-in support for AJAX (or just JS) enabled elements on the page to remove a bunch of handwritten view code.
ORM Integration
While CI's built-in DB abstraction is rather solid, having an easier method of hooking in Doctrine (or Propel, if you're so inclined) would very much be a welcome improvement.
conclusion:
If you are developing PHP apps the old fashioned way: with lots of includes, tons of business logic and HTML wrapped up in every PHP file, and calling *sql_query || die() constantly, you absolutely owe it to yourself to try CodeIgniter.
@ckh2oman