At the end of January 2011, Codeigniter released its new version, 2.0. As expected, they made a number of major changes and added some awesome features to this new version. Besides, they made some other changes also on development work-flow etc recently. In this article, my concern is to make existing Codeigniter developers familiar with this new version and its features/enhancements, as well as with the other recent changes. However, new Codeigniter developers may get some idea, too.
PHP Version Supports:
From this new version, 2.0, Codeigniter is going to support only php 5+. Mention before, Codeigniter 1.x versions supported php 4 and PHP 5 both versions. Now, PHP 4 support is simply gone. So, if you are a PHP developer who writes php 4 compatible codes often, you should refine yourself a little before starting with Codeigniter 2. A simple example of a controller class written in 2 different PHP versions is as follows:
<?php
/*PHP 4 based, won’t work with codeigniter 2 */
class MY_Controller extends Controller {
function MY_Controller()
{
parent::Controller();
// Your own constructor initialization codes
}
}
/*PHP 5 based, will work with codeigniter 2 and previous versions also*/
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
// Your own constructor initialization codes
}
}
?>
Code language: HTML, XML (xml)
Directory Structure Changes:
Before, Codeigniter had the directory structure like this: application directory was in {root}/system/applications/ and other system files was in {root}/system/ directory. In the new Codeigniter 2.0, this structure changed and the application directory came free as an external directory. So, now default application directory will be {root}/applications/ and other Codeigniter core files/directories are on {root}/system/ folder. Although it is possible for everyone to made this change themselves, still I think this is a great idea to make this change officially. As you won’t have to look into system directory at all unless you are going there to learn something from the core. This helps developers to navigate application directories from ide(Integrated Development Environment) easily than before. Besides, this will help you to set up multiple web application more easily.
Codeigniter 2 plugins:
If you were using plugins in Codeigniter. You may get surprised to listen that, Codeigniter 2 doesn’t support plugins anymore. Who will do the tasks then? Well, simply use helper and hooks to achieve whatever you need. Won’t be difficult at all, right?
Codeigniter 2 routing enhancement:
There is 2 more useful enhancements on codeigniter 2.
- common override rules: Now, we can write/override common rewrite/routing rules to the index.php files also. This will be helpful if you are using multiple application in a single installation. Other application specific routing rules can still be written in routes.php in the application/config/ folder.
- New routing override rule: New default rule added for 404 error pages. That means you can now use “$route[‘404_override’]” to route a 404 page to a specific controller methods you like.
Condeigniter 2.0 Supports caching:
This new version supports dynamic caching. You can have total control of what you are caching. A simple example of how caching works:
if ( ! $myvar= $this->cache->get(‘myvar’))
{
//assign any kind of data/objects which are to be cached
$myvar = ‘simple text’;
// Save into the cache for 5 minutes
$this->cache->save(‘myvar’, $myvar);
}
//use the variable normally
Code language: PHP (php)
It supports the following forms of caching:
- Alternative PHP Cache (APC) Caching. To know more details about APC caching, please visit APC caching
- Memcached Caching. To know more about memcached caching, please visit Memcached Caching
- File-based Caching. To supports caching in raw text files. It is a good option if you don’t have support for any of the above.
Condeigniter 2.0 Provides 2 different Flavors:
From this new version, there will be 2 different development version will be available:
- CodeIgniter Core : This development will be move on by support of Ellislab themselve, thus we can say of it as the official version. However, its new releases will be much slower.
- CodeIgniter Reactor This is the version, where Codeigniter community contribute and enhance the Codeigniter core functionality. This includes a lot of community driven implementation integrated on the core. This version is to be changed/enhanced frequently.
I prefer the reactor version and Codeigniter itself prefer so. Because, it will help you avoid reinventing wheel in many phases of development. Also, even some of the features i have discussed here, are provided by reactor community.
Read The Complete CodeIgniter Tutorials Series By CodeSamplez.com
References:
If you are interested in knowing every single detail about the new changes and enhancements, please visit Codeigniter 2.0 Changelogs. Happy coding 🙂
Stas says
Codelobster PHP Edition already supports CodeIgniter 2.0. too.
Julian says
Thanks for the insights !
DerekPadula says
That was helpful. I’m working with CodeIgniter 2.0 right now. Thank you.