CodeIgniter 2.0 is out with cool features!

Posted by Danny Herran on Feb 13, 2011 in Backend | 4 comments

I know its a bit late, CI 2.0 has been out since January 28th, 2011, but lets talk about it anyway and recapitulate some of the new features of this framework. The new stuff is great, and this time I believe it deserves a second look if you are not much into CI.

Let me thank in advance the guys of the CI team for their great work.

First of all, CodeIgniter for us the mortals, is now called CodeIgniter Reactor. There is a new slow-moving branch of the project called CodeIgniter Core which will be used as the base for EllisLab commercial products such as ExpressionEngine and MojoMotor. So, what you need to download and use from now on is CodeIgniter Reactor. Put simply, Reactor = CodeIgniter.

According to the official CI official announcement, here’s what we have:

  • Support for PHP 4 is gone, PHP 5.1 is now a requirement: Finally, it was needed, really. PHP 5 offers much more flexibility in OOP and it was a waste not to take fully advantage of these features. PHP 4 has been officially phased out anyway. I believe the people who moved away from CI to Kohana for the sake of PHP5, may want to take a look at the new CI.
  • CSRF Protection built into the form helper: For those who don’t know what CSRF, it means Cross-site request forgery. It is a wide term, but in this particular case, it will prevent “form-forgery”, since the new form helper will include security measures to prevent hackers faking our web forms. I haven’t tried this myself, but as soon as I get more info about this, I’ll make sure to update the post.
  • Drivers: Definition by EllisLab: “Drivers are a special type of Library that has a parent class and any number of potential child classes. Child classes have access to the parent class, but not their siblings. Drivers provide an elegant syntax in your controllers for libraries that benefit from or require being broken down into discrete classes”. The new drivers are the Caching, Database and Javascript class (yep you can initialize jQuery from CI now).
  • Application Packages: As defined by Phil Sturgeon: “It basically allows you to set extra directories that contain libraries, models, helpers, etc. Using $this->load->add_package_path() you can set any full server path to use any shared location you like. No more faffing with symlinks or infecting system/libraries with your third party code.” This means that now you can have a common area to place all your libraries, helpers, config files that can be used by your applications. Maybe shared helpers for your frontend and backend area? You decide.
  • Scaffolding, having been deprecated for a number of versions, has been removed: Was about time, this feature has been dead for several versions. It was used to add/edit/delete records from a database, a simple CRUD, it was only useful for operational presentations, nothing more.
  • Removed the deprecated Validation Class: It was replaced by the Form Validation Class a few versions ago, but it seems like they decided to remove it just now. Just like they did with the Scaffolding class.
  • Plugins have been removed, in favor of Helpers: IMHO plugins were a bit redundant, since you could do almost the same with helpers+libraries. So, I am glad the removed it, it also prevents confusing the new adopters of the framework.
  • Added routing overrides to the main index.php file, enabling the normal routing to be overridden on a per “index” file basis: Waiting for clarification from someone on the CI dev team.
  • Added $route[‘404_override’] to allow 404 pages to be handled by controllers: Excellent and beautiful feature, now we can have “smart” 404 pages, handled by their own controllers. Kinda nice isn’t it?
  • 50+ bugs fixed: I can’t go into detail here, since I have no list of every specific bug, but if there were bugs and they fixed them, it’s something good.

And the following features are only present in CodeIgniter Reactor (the one you should use):

  • Full query-string support: Now the $_GET superglobal is automatically supported by CI. No more workarounds, hacks and ugly patches. There is always the option to disable this feature in the config file of course.
  • Automatic base_url detecion if left blank: If you leave this parameter empty in the config file, CI will automatically detect your base_url.
  • New Cache driver with file system, APC and memcache support: Even if you need the drivers installed in your server to take advantage of these features, it’s nice to know they are there. Check the official CI cache documentation for more details about this.
  • Command line compatibility for easy cron jobs: Before CI 2.0, if you wanted to run a Controller from a cronjob, you needed to use curl or get. If you tried php /var/www/path/to/your/script, it wouldn’t work because CI wasn’t able to initialize its main core libraries. The problem with that is that it takes too much CPU resources, and from my experience, cronjobs are usually server-side intensive. From now on, CI will have full command line compatibility to ease your cronjob execution.
  • 20+ tweaks and improvements: Table class, new classes, drivers, etc.

Make sure you download the latest version from the official CI website:

And if you need Modular Extensions for 2.0: