Adam has authored CodeIgniter 1.7 Professional Development; the first advanced CodeIgniter book, gives an overview of what's new with CodeIgniter 2.0, how to upgrade your applications and a detailed overview of how to create drivers.
53. // ... save the original view path, and set to our package view folder $orig_view_path = $this->load->_ci_view_path;$this->load->_ci_view_path = APPPATH.'third_party/package_name/views/';// ... code using the package's view files// ... then return the view path to the application's original view path$this->load->_ci_view_path = $orig_view_path; $orig_view_path = $this->load->_ci_view_path;$this->load->_ci_view_path = APPPATH.'third_party/package_name/views/';// ... code using the package's view files// ... then return the view path to the application's original view path$this->load->_ci_view_path = $orig_view_path; $orig_view_path = $this->load->_ci_view_path;$this->load->_ci_view_path = APPPATH.'third_party/package_name/views/';// ... code using the package's view files// ... then return the view path to the application's original view path$this->load->_ci_view_path = $orig_view_path;
Hello, I’m going to be talking to you today about CodeIgniter 2, the in development version of CodeIgniter. My name is Adam Griffiths and before I dive into my talk I wanted to go through who I am and why you should listen to me!
Ok so I’m Adam Griffiths. I created and authored all of the tutorials on Programmers Voice. This was a hugely popular CodeIgniter focussed tutorial blog where I posted tutorials, articles and screencasts on CodeIgniter and supplementary subjects such as jQuery and Git. I am the guy behind AG Auth, quite possibly the eaisest Authentication Library for CodeIgniter, just extend a new Controller class to get a full authentication system with admin panel! I also created AG Asset, another simple library that enables you to manage your CSS files, images and script files and provides an easy way to pre-load CSS and JavaScript if you have a lot of files to include. Finally I am the author of CodeIgniter 1.7 Professional Development, the first advanced book on CodeIgniter covering topics such as User Authentication, Twitter oAuth, Facebook Connect, Web Services and REST, and a neat little chapter with ym tips on releasing code to the community.
On with the talk. So, CodeIgniter 2. It’s a bit of a jump from 1.7.2. In this talk I’m going to take you though all of the things that have been removed (and what you should use in it’s place), everything that’s now deprecated. We’ll also look at all the changes in CodeIgniter 2 and finally all the new goodies we get to play with. I’ll also give you a few tips for upgrading your projects to CodeIgniter 2.
Goodbye Scaffolding. Scaffolding was a way to easily create records in your database, kind of like a mini PHPMyAdmin. But it wasn’t a very good implementation. You would set a scaffolding key and turn it on in your controllers, but if somebody knew your key they could easily start to mess around with your data if you didn’t turn it off on a production server. Scaffolding has now been removed for CodeIgniter 2.0.0.
Au revoir plugins. Now I didn’t really expect plugins to be removed without first being deprecated, but I’m not all that surprised it’s been removed either. Plugins have been removed in favour of helpers, and now many people knew what plugins were for. I know that plugins were supposed to be community created and be single purpose, they should have only one function in them. Helpers were supposed to be created by EllisLab and be more official and multi-purpose. But people used the two interchangably as they were extremely similar to each other. So if you’re still using plugins you should update these to be helpers.
The Validation Class has also been removed after being deprecated since v 1.7.0. Version 1.7.0 saw the Form Validation Class being added to the framework in place of the Validation Class. Therefore you should use the more powerful Form Validation Class.
PHP 4! There have been numerous forum posts, tweets, blog posts and I have even had a few emails asking when CodeIgniter was going to drop support for PHP 4. Ellis Lab have always said they will only drop support for PHP 4 when the user base becomes small enough that when the change occurs they’re not putting a considerable amount of developers out in the cold. New CodeIgniter 2 features may not support PHP 4, it might work but nobody cares. All legacy features will no longer have support for PHP 4 as of 2.1.0.
Ok so a quick show of hands. How many of us here move the application directory out of the system directory before starting a project? This won’t be an issue in CI 2 as the application directory now exists in the top level alongside the system folder and the index.php front controller. I know it’s never been exactly hard to move the application directory, you literally just move it, no need to edit any settings but Ellis Lab have obviously seen that a lot of people do this anyway, and it’s always good to have clear separation so in CodeIgniter 2, we’ll be able to just jump into the code rather than spend (albeit a minute) time moving directories.
Ok so onto the index.php front controller. Nothing major has been changed here but there’s a few things you might like to know. You can now store configuration values in this file. This allows you to share one application between multiple front controllers using different configuration values. Routing overrides have now been added to this file as well. This allows you to set your default controller in this file rather than your routes.php configuration file. However, using this method will limit your application to one controller, although you will still be able to call different functions in that controller.
Ok so now we’re getting into the good stuff. So what’s new?
We’ll kick this section off with a biggy. Drivers. Drivers are a new type of library with CodeIgniter 2.0.0. They allow you to have a parent class with any number of child classes. Children can access functions of their parent, but not their siblings. An example of a library that would take advantage of this new type of library is the Database Library.
Ellis Lab have now started to host their in-development code on BitBucket, the github for mercurial hosting. Mercurial is a distributed version control system much like git. This is good for a few reasons. Firstly it’s easier to get your own code in the CodeIgniter core. Whereas it was possible before it’s much easier to issue a pull request than the older channels. It also allows the community to help squish bugs, and in a few cases a community member has been given responsibility for a few support tickets. And finally, no subversion!! I really hate SVN, so this is the best thing for me!! :)