Upgrading to CodeIgniter 2.0
Posted CodeIgniter at May 05, 2010
As soon as I saw the tweet from EllisLab that CodeIgniter 2.0-dev was available on BitBucket I instantly converted PyroCMS to run on it. I got it all working in a few hours after LOTS of headbanging, mouse throwing and blaspheming. All the bugs I found along the way have since been fixed in the 2.0 branch by the Ellis developers or myself.
While this does not mean everything is running perfectly, at the time of writing all the worrying bugs are squashed so it should be safe for us to have a play.
Grab those new files
Download the new files from BitBucket.
What goes where
Slight change in the folder structure for some of you, the application/ folder and the system/ folder now sit next to each other.
So move your application folder up one level to sit next to system/ then delete that system/ folder. That his killed off CodeIgniter 1.7.2. Bye!
Now you need to copy the new downloaded system/ folder to the empty gap where the old one was.
Sadly that is not entirely it. You must also copy the following files from the new download to your installation:
- index.php
- application/config/foreign_chars.php
- application/config/profiler.php
Noticed that your models are broked?
CodeIgniter Models used to use the following class definitions:
class Blog_model extends Model
Now in CodeIgniter 2.0 you write:
class Blog_model extends CI_Model
Let's not argue about why, what, who, where, when as this may still change. For now, the fact is you have to do this. It can be achieved with some simple Find & Replace over your folder if your IDE/Text editor will allow it. Nearly there now unless you use plugins or the old Validation class.
Oh shit, I use plugins!
Well not any more you don't. Plugins are dead and gone so you need to convert them to be Helpers. Move them to the application/helpers and rename from "whatever_pi.php" to "whatever_helper.php". Theoretically there is more to what should be a plugin or helper than the name of the file but TBH they will work like this so who gives a damn at this stage?
Make sure you have moved any array values in application/config/autoload.php from $autoload['plugins'] to $autoload['helpers'] or you will notice stuff break.
Validation is no more
You all had fair warning, it has been deprecated for several versions and now it is gone completely. You can:
A.) Move to using the new Form Validation class.
B.) Grab the old Validation.php class and put it in your application/libraries/ folder.
C.) Whine like a little girl on the forums.
Strange change to $config['permitted_uri_chars']
I had to change "a-z 0-9~%.:_-" to "a-z 0-9~%.:_-" in my application/config/config.php. Notice the backslash () before the hyphen (-).
Modular Separation
Out of the box Modular Separation won't work with CodeIgniter 2.0. Good thing I picked up the project and released a patch then huh? Grab the latest version in the 2.x branch from the Modular Sepearation Wiki.
CI_Language has a new name
The core library CI_Language has been renamed to CI_Lang. For 80% of apps this will mean nothing at all. If you refference the library or extend it then you will of course need to rename this.
Deprecated DB methods removed
After being deprecated since 1.6.x we finally see the back of the DB methods orwhere, orlike, groupby, orhaving, orderby and getwhere. They should now be or_where, or_like, group_by, or_having, order_by and get_where which is just a few more find/replace changes to run on your projects.
Disable query strings or expect weirdness
This didn't happen in previous CodeIgniter versions but in 2.0 if you enable $config['enable_query_strings'] it will now generate links like http://example.php/index.php?/controller, or http://example.php/?/controller. You need to set enable_query_strings to false which will disable GET support. You can re-enable that with a MY_Controller or hook that runs:
parse_str($_SERVER['QUERY_STRING'], $_GET);
Summary
That should be it! Up and running on CodeIgniter 2.0. Most of you won't need to have bothered with all the steps but they are worth keeping in mind for the future. If you spot anything I have missed please pester me in one of the usual ways.
Comments