Phil Sturgeon

Web developer, kayaker, outdoors madman and part-time alcoholic.


CodeIgniter 2.0: Everything you need to know

Posted CodeIgniter at Mar 11, 2010

It has been 6 months since the last CodeIgniter minor update and 18 months since the last major update. Through all this time we were given no information about the next release of CodeIgniter, but finally 2.0 is on the way.

The EllisLab team have decided to drop Subversion, use Mercurial, track their tickets on Assembla and host their code on BitBucket

So what?

The change of Version Control System to us (the general public) makes no real difference, but it wil let the team work much quicker.

The change to Mercurial would not be as interesting if it was not for the fact they were hosting the code on BitBucket, which is the Mercurial equivilent of GitHub. This is potentially the best piece of news in this entire article.

By moving to a social-coding platform like this, CodeIgniter can face the same attention from the community that jQuery and CakePHP have recently recieved. jQuery 1.4 massively benefited by being moved to GitHub, as v1.4 was made up almost entirely of community patches and suggestions.

Essentially, if you spot a bug then you can fork CodeIgniter and make the change. Then if they like it, it may well get added in. Win!

What about the code?

Well, there are a LOT of changes in the Changelog for 2.0 so far. Many of these are small tweaks, but the best?

PHP 4 support is deprecated. Features new to 2.0.0 may not be support PHP 4, and all legacy features will no longer support PHP 4 as of 2.1.0.

Well thank fuck for that. It was not a huge suprise as ExpressionEngine 2.0 had dropped support for PHP 4, but the fact it has come down to CodeIgniter is brilliant. It means slowly but surely CodeIgniter can progress forwards with great new features without having to worry about coding it in a long-winded PHP 4 compatible fashion.

Drivers

Drivers are a really useful feature that Kohana has had implemented for a while, but is rather difficult to explain. I'll let EllisLab do it for me:

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.

A great example of this is the new JavaScript library. That is the main "parent" class, then the jQuery "driver" inherits and does more specific code.

Another example could be a Cache class, which then has File, Memcache, APC, etc as drivers.

Application "Packages"

This is a feature I have wanted for as long as I have been using CodeIgniter. It basically allows you to set extra directories that contain libraries, models, helpers, etc.

Example:

/system/application/third_party/foo_bar

config/
helpers/
language/
libraries/
models/

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.

Core libraries

Core libraries like Router, Loader, Output, etc are all system/core, but look like they can still be extended/replaced by placing yours in system/application/core.

Reserved Controller Names

The "reserved controller name" list is now tiny (if you are using PHP 5). They can be anything other than:

That gives you a LOT more flexibility on what you can call your controllers after the massive list in PHP 4 support.

More database config

The most exciting of the lot there for me is stricton. I have had some real problems with PyroCMS on MySQL Strict Mode installations as my local environment is not strict. Using this switch you can just turn MySQL Strict Mode on and make sure it lets you know about any possible errors that would occur if you were running using Strict Mode.

Goodbye plugins!

Plugins have been removed which should really help with the "Library, Helper or Plugin?" confusion. Now your code can be boiled down much eaiser:

Helpers - One or more functions
Libraries - Lots of functions that share properties (and therefore needs to be a class)

Now the ambiguous "Plugins" have been replaced this is a much easier choice, as previously a plugin could be a function or a class. This should be the hardest upgrade step, but essentially all you need to do is find & replace "load->plugin(" with "load->helper(" and move system/application/plugins/foo_pi.php to system/application/helpers/foo_helper.php - no biggy.

Summary

By the looks of it, CodeIgniter 2.0 brings along some brilliant new changes, a heap of bug-fixes for us to be content with. Nothing massive, nothing scary and nothing incompatible. With PHP 4 support on the way out we can all dance a little jig and look forward to a much more interesting future in CodeIgniter feature development.

For now, check out the Changelog and subscribe to the RSS feed or follow the BitBucket project to keep up to date with the progress.

Edit: Michael Wales and Elliot Haughin have also written their views on the new CodeIgniter 2.0 announcement. Read their articles to get a good base of opinions on the subject.

Comments

User comments
  • Gravatar Lukas

    Jun 11, 2010

    I'm planning to switch to CI 2.0. Is it compilant with 1.x release?

  • Gravatar Aditia

    May 11, 2010

    great i never use plugin anyway, and hoping using more oop function like kohana

  • Gravatar Scott

    Apr 20, 2010

    "Well thank fuck for that." - spot on, best news I've heard re: codeigniter in a long while.

  • Gravatar Zeeshan Rasool

    Apr 13, 2010

    Great work Phil. Hope it will be a great achievement for Codeigniter

  • Gravatar Brian Gottier

    Apr 11, 2010

    It's exciting to think about a new version of CI and the features you describe, but I guess I was hoping for more. I know you said this article just shares what you think are the best changes, and I hope we are really amazed when CI 2.0 finally comes out.

  • Gravatar Taner Ozdas

    Apr 01, 2010

    Good decision.

    I have been using Mercurial more than 2 years , for my projects. I think it is really better than svn.

    I am also looking forward to see how will be the codeigniter ver 2.

    Thanks for this post.

  • Gravatar Nurul Ferdous

    Mar 31, 2010

    yo CI rules!

  • Gravatar Mahbubur Rahman

    Mar 24, 2010

    Looks like CI is reaching more standard and maturity and a good answer to some people who call CI childish :)

  • Gravatar Phil Sturgeon

    Mar 22, 2010

    @Jorge: They plan to introduce modularity some time. It's not that they "did not think of it", they have a plan they are sticking to that involved keeping EE2 stable. They wont just throw features into CI for the sake of it.

    @William: You'll be fine learning CI 1.7.2, the syntax, libraries, etc are all directly transferable as this is not a "massive change" as people keep pointing out. It could just as easily be called v1.8, I assume v2.0 was made to match the ExpressionEngine version bump.

  • Gravatar William

    Mar 18, 2010

    Hi Phil, Question, I've been with CI like 2 years not (on and off actually)but right now I want to re-start digging through the CI current release, I plan to explore it to the extend of its capabilities, do you think it is still practical for me to do that now, since sooner CI2.0 will going to be release with new features or so? Hope you can provide me some light here.

    Many Thanks!

  • Gravatar Jorge

    Mar 16, 2010

    Hi Phil, hi everybody. EllisaLab doesn't think about introduce the concept of modules like HMVC or Matchbox? Or introduce ORM for deeply relationships between tables?

    And what about PHP6 and the concept of namespaces? I know is very soon but think about, in the future CI changes totaly again? Nevermind, I think that is so far yet.

    Greettings from Spain!

  • Gravatar Manuel Joao

    Mar 16, 2010

    Hey Phil,

    Tks for the article, just one thing is missing, the release date, I know open projects can't/usually don't have strict release date, but what's your option about it, can we expect v2.0 still this year?

    Do you (or any other speaker) plan in taking v2.0 to CI Bristol conference?

    cheers

  • Gravatar Valcapri

    Mar 15, 2010

    I like to see CodeIgniter going to 2.0. It's happy to see that EllisLab dropped the PHP4 backward compatibility. We will probably see a better OOP code and PDO.
    I switched to Mac OS X.
    Is there a Git or a Mercurial GUI for Mac OS X? And which IDE are you for developping with CodeIgniter?

    Thanks for reply

  • Gravatar Dan

    Mar 15, 2010

    Just an FYI. You can see the docs on the Javascript Library online:
    http://bitbucket.org/ellislab/codeigniter/raw/dd6ef20b745a/user_guide/libraries/javascript.html

    And the jQuery Class:
    http://bitbucket.org/ellislab/codeigniter/raw/dd6ef20b745a/user_guide/libraries/jquery.html

  • Gravatar Mtr

    Mar 15, 2010

    Great to see new update of CI.

    When will be planned to release for testing?

  • Gravatar Phil Sturgeon

    Mar 15, 2010

    @Eric Barnes: I noticed this too, I wasn't sure if the problem was PyroCMS related and didn't get around to checking. The new user_guide suggests "class Blogmodel extends Model {" should still be valid syntax, so I raised an issue on BitBucket.

    @Otar Chekurishvili: Me too, it's had me confused since December...

    @Joel Gascoigne: BitBucket to me is the best part. If they have the time to go through people's pull requests then this will be amazingly powerful. Derek Jones suggested to me that they wouldn't have the time and that's why they wouldn't move to GitHub, so it's left me a little confused but hopeful.

  • Gravatar Eric Barnes

    Mar 15, 2010

    Very good write up. The first thing I noticed that may in fact be a bug is that it seems I have to extend CI_Model instead of Model.

    Also with the add_application_path it would be awesome if it would support everything like modular extensions. I haven't tested this out but it seems to me if you add a bunch of extra application paths it may affect performance. But a great improvement none the less and I can see lots of awesome things these can be used for.

  • Gravatar Otar Chekurishvili

    Mar 12, 2010

    I still don't understand how JavaScript library will work in the real situations.

    Some basic examples needed...

  • Gravatar Yoosuf

    Mar 12, 2010

    Good read, the article gave me a good view of 2.0 CI, hope CI will be open source for further more

  • Gravatar Benjamin Falk

    Mar 12, 2010

    @Ben Edmunds
    Agreed. That's a pretty common complaint, and perhaps will encourage some who might go to other frameworks (Cake, Kohana, etc) to take a second look.

  • Gravatar Joel Gascoigne

    Mar 12, 2010

    Wow, this is all great news, thanks for summarising everything :)

    Drivers will bring a better way to do something I've been hacking a little so far.

    I'm glad PHP4 support is being dropped, that combined with using BitBucket should increase velocity. Oh, and maybe I'll get involved now :)

  • Gravatar Phil Sturgeon

    Mar 12, 2010

    @Emmanuel Okorie: Believe it or not I was feeling the same. Yesterday I finally caved in to Jamie Rumbelow and Elliott Kembers constant Rails ear-bashing and decided to give it a try, failing that Symphony. But right as I was installed RoR, I spotted a tweet from EllisLab. It's like they knew.... :-o!

    @Davebowman: I know exactly what you mean and I have argued against those idtiots for years. The PHP 4 base was mainly optional as Base4.php and Base5.php worked very differently to provide the same base in the best way for that version.

    However, it did mean that certain features could not be added into the core unless there was a PHP 4 alternative, which sucked. This is a step towards getting past that.

  • Gravatar Davebowman

    Mar 12, 2010

    I'm always confused with statements like that - "I would like to use CodeIgniter, but gee, it still has PHP4 support". Well, it does, but not in the sense *you* have to write v4-compatible code.

  • Gravatar Ben Edmunds

    Mar 11, 2010

    I think the thing I'm most looking forward to is no more whining in the forums about PHP 4 support...

  • Gravatar Emmanuel Okorie

    Mar 11, 2010

    Certainly looking good... I am glad to have stuck with CodeIgniter, was itching to start working with PHP5 properly and had considered Kohana but decided against it. If EllisLab are planning to phase out php4 support, that is all the motivation I need.

Post a comment