Wednesday, 16 June 2010

CodeIgniter - The next natural step

Most web developers have their own code base that they refer back to on a regular basis. Many have even developed their own simple platforms that do a lot of the leg work for them, that they know inside out and can easily deploy on a new project.

More recently though, at least in the last 4-5 years, frameworks have been popping up left right and centre. From CakePHP, which is generally considered to be a little unstable, to the super-reliable ZendFramework, built by Zend - the PHP company.

Zend and Cake are not he only frameworks though. After trying a lot, I find my personal favourite to be CodeIgniter, which is built by EllisLabs.

CodeIgniter comes with libraries and helpers that can be activated at any point within the framework. These helpers try and simplify many tedious tasks involved with making web applications. Things like form validation is a breeze, and the functions used are much more powerful than something that can be drummed up quickly in any normal PHP app. Image manipulation is made easy, and emailing through PHP can be done well without needing to load in the bloated PEAR, which the documentation recommends.

CodeIgniter uses standard MVC (Model > View > Controller) to create it's systems. Although at first glance this can seem a little silly and over-thought, but it makes life a lot easier for everyone involved. The MVC structure is standardised, reliable and fast, and every developer should follow suit with it very easily.

CodeIgniter also makes debugging applications very easy. The built-in profiler shows all of the POST, and GET data, aswell as all database queries. I used a customised version of the profiler that I tweaked to also show SESSION data.

When working with lots of small, simple queries CodeIgniter also makes life easy with active records, their database library. It allows queries to be written with a fraction of the amount of code. Let's say we want to pull off everything from a table, simple: db->get('table') - no need to write a full query to do it. Active records do support large queries with unlimited amounts of JOINs, but my personal preference is to compile these myself and throw them into a normal query using the DB library's db->query() method - probably because I'm used to the structure of the queries and the syntax so I can spot errors more easily. If you're not hot on SQL though, you'll probably benefit massively.

My personal framework recommendation is definitely CodeIgniter, but make sure you check out all of the others available too. CodeIgniter has a massive community that helps solve any problem you may have, the community includes forums and live chat rooms, which the EllisLabs developers often frequent.

No comments:

Post a Comment