You are on page 1of 71

CodeIgniter 2.0.

0
Adam Griffiths

@adam_griffiths adamgriffiths.co.uk

adam@adamgriffiths.co.uk bitbucket.org/adamgriffiths/

Who am I?
Author of programmersvoice.com AG Auth - Easiest Auth Library for CI AG Asset - simple Asset Management Library Author of CodeIgniter 1.7 Professional Development

CodeIgniter 2.0.0
Whats been removed Whats been deprecated Whats changed Whats new Tips for upgrading

Whats been removed

Goodbye Scaffolding
Deprecated for a number of versions Wasnt a very good implementation Has now been removed for CodeIgniter 2.0.0

Au revoir Plugins
Removed in favour of Helpers Nobody was ever sure what they were for Plugins & Helpers were too similar You should update your Plugins to Helpers

Validation Class
Deprecated since 1.7.0 More powerful Form Validation Class should be used
instead

Deprecations

PHP 4
Support now dropped for PHP 4 YAY!! New CI 2 features may not support PHP 4 All legacy features will no longer support PHP 4 as of
2.1.0

Changes...

Application Directory
How many of you move your application directory out of
the system directory?

That wont be an issue in CI2

index.php
Configuration values can now be stored here. Allows a single application to have multiple front
controllers with different configuration values.

Routing overrides now added. Limits your application to one controller.

Whats new?

Drivers
New type of library Parent class and any number of child classes CI Database Library could be a Driver

Using Drivers
$this->load->driver(driver_name); $this->driver_name->method(); $this->driver_name->subclass->subclass_method();

Creating a Driver

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

File Structure
application/ libraries/ driver_name/ Driver_name.php drivers/ Driver_name_subclass_1.php Driver_name_subclass_2.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser File Structure


application/ libraries/ Parser/ Parser.php drivers/ Parser_dwoo.php Parser_smarty.php

Parser.php Class
<?php class Parser extends CI_Driver_Library { } // class ?>

Parser.php Class
<?php class Parser extends CI_Driver_Library { } // class ?>

Parser.php Class
<?php class Parser extends CI_Driver_Library { } // class ?>

<?php

class Parser extends CI_Driver_Library {


function __construct() { $this->valid_drivers = array('parser_dwoo', parser_smarty); } // _construct()

} // class
?>

function __construct() { $this->valid_drivers = array('parser_dwoo', parser_smarty); } // _construct()

Parser_dwoo.php Class
<?php class Parser_dwoo extends CI_Driver { } // class ?>

Parser_dwoo.php Class
<?php class Parser_dwoo extends CI_Driver { } // class ?>

Parser_dwoo.php Class
<?php class Parser_dwoo extends CI_Driver { } // class ?>

Packages
Allows for easy distribution of resources in a single
directory.

Can have its own library files, models, config files etc. Placed in application/third_party MojoMotor addons are packages

Creating a Package

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Package File Structure


application/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/

Add Package Path


Before you can load a package, you need to tell the
Loader where to look for it.

$this->load>add_package_path(APPPATH.'third_party/package_n ame/');

$this->load->library(package_name);

Remove Package Path


When finished using a Packages resources. When you want to use multiple Packages. $this->load>remove_package_path(APPPATH.'third_party/packag e_name/');

Package View Files


Disclaimer: not finished Save the original view path Set the view path to that of the Package Load views, etc Set the path back to the original

// ... 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;

Mercurial/BitBucket
In development code is now hosted on BitBucket Easier to get *your* code in the CI core Allows community to help squish bugs No SVN!! (Sorry but I really do hate Subversion)

Quick and Dirty Mercurial Tutorial

The Basics
hg init hg pull <url> hg pull <constant> hg pull <path/to/local/repo> hg update

Continued...
hg diff hg add . hg add <path/to/file> hg commit -m Commit Message hg push <url> hg push <constant>

.hgrc file
mate $HOME/.hgrc [paths] ci_master = http://bitbucket.org/ellislab/codeigniter/

Upgrading Tips

Upgrading your Models

CodeIgniter 1.7.2 Models extend Model CodeIgniter 2.0.0 Models extend CI_Model

Lazy mans Model Upgrade


Create a new Library file: MY_Model.php
<?php class Model extends CI_Model { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Model Upgrade


Create a new Library file: MY_Model.php
<?php class Model extends CI_Model { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Model Upgrade


Create a new Library file: MY_Model.php
<?php class Model extends CI_Model { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Model Upgrade


Create a new Library file: MY_Model.php
<?php class Model extends CI_Model { function __construct() { parent::__construct(); } // construct() } // class ?>

Controllers
Controllers are currently unchanged Ellis Lab are evaluating changing the Controller class
from Controller to CI_Controller

Lazy mans Controller Upgrade Create a new Library file: MY_Controller.php


<?php class Controller extends CI_Controller { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Controller Upgrade Create a new Library file: MY_Controller.php


<?php class Controller extends CI_Controller { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Controller Upgrade Create a new Library file: MY_Controller.php


<?php class Controller extends CI_Controller { function __construct() { parent::__construct(); } // construct() } // class ?>

Lazy mans Controller Upgrade Create a new Library file: MY_Controller.php


<?php class Controller extends CI_Controller { function __construct() { parent::__construct(); } // construct() } // class ?>

Summary
Plugins, Validation Library & Scaffolding have been
removed

PHP 4 support dropped Drivers & Packages Model Class renamed Mercurial/Bitbucket

Q&A
@adam_griffiths www.adamgriffiths.co.uk Skype: adam-griffiths www.bitbucket.org/adamgriffiths/ adam@adamgriffiths.co
.uk

You might also like