CICON2010: Adam Griffiths - CodeIgniter 2
-
Upload
codeigniter-conference -
Category
Documents
-
view
5.417 -
download
0
description
Transcript of CICON2010: Adam Griffiths - CodeIgniter 2
![Page 1: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/1.jpg)
CodeIgniter 2.0.0Adam Griffiths
@adam_griffiths
adamgriffiths.co.uk
bitbucket.org/adamgriffiths/
![Page 2: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/2.jpg)
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
![Page 3: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/3.jpg)
CodeIgniter 2.0.0
•What’s been removed
•What’s been deprecated
•What’s changed
•What’s new
•Tips for upgrading
![Page 4: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/4.jpg)
What’s been removed
![Page 5: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/5.jpg)
Goodbye Scaffolding
•Deprecated for a number of versions
•Wasn’t a very good implementation
•Has now been removed for CodeIgniter 2.0.0
![Page 6: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/6.jpg)
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
![Page 7: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/7.jpg)
Validation Class
•Deprecated since 1.7.0
•More powerful Form Validation Class should be used instead
![Page 8: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/8.jpg)
Deprecations
![Page 9: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/9.jpg)
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
![Page 10: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/10.jpg)
Changes...
![Page 11: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/11.jpg)
Application Directory
•How many of you move your application directory out of the system directory?
•That won’t be an issue in CI2
![Page 12: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/12.jpg)
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.
![Page 13: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/13.jpg)
What’s new?
![Page 14: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/14.jpg)
Drivers
•New type of library
•Parent class and any number of child classes
•CI Database Library could be a Driver
![Page 15: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/15.jpg)
Using Drivers
•$this->load->driver(‘driver_name’);
•$this->driver_name->method();
•$this->driver_name->subclass->subclass_method();
![Page 16: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/16.jpg)
Creating a Driver
![Page 17: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/17.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 18: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/18.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 19: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/19.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 20: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/20.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 21: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/21.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 22: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/22.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 23: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/23.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 24: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/24.jpg)
File Structureapplication/
libraries/driver_name/
Driver_name.phpdrivers/Driver_name_subclass_1.phpDriver_name_subclass_2.php
![Page 25: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/25.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 26: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/26.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 27: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/27.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 28: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/28.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 29: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/29.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 30: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/30.jpg)
Parser File Structureapplication/
libraries/Parser/
Parser.phpdrivers/Parser_dwoo.phpParser_smarty.php
![Page 31: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/31.jpg)
Parser.php Class<?php
class Parser extends CI_Driver_Library {
} // class
?>
![Page 32: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/32.jpg)
Parser.php Class<?php
class Parser extends CI_Driver_Library {
} // class
?>
![Page 33: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/33.jpg)
Parser.php Class<?php
class Parser extends CI_Driver_Library {
} // class
?>
![Page 34: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/34.jpg)
<?php
class Parser extends CI_Driver_Library {
function __construct() {$this->valid_drivers = array('parser_dwoo', ‘parser_smarty’);
} // _construct()
} // class
?>
![Page 35: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/35.jpg)
function __construct() {$this->valid_drivers = array('parser_dwoo', ‘parser_smarty’);
} // _construct()
![Page 36: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/36.jpg)
Parser_dwoo.php Class<?php
class Parser_dwoo extends CI_Driver {
} // class
?>
![Page 37: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/37.jpg)
Parser_dwoo.php Class<?php
class Parser_dwoo extends CI_Driver {
} // class
?>
![Page 38: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/38.jpg)
Parser_dwoo.php Class<?php
class Parser_dwoo extends CI_Driver {
} // class
?>
![Page 39: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/39.jpg)
Packages
•Allows for easy distribution of resources in a single directory.
•Can have it’s own library files, models, config files etc.
•Placed in application/third_party
•MojoMotor addons are packages
![Page 40: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/40.jpg)
Creating a Package
![Page 41: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/41.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 42: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/42.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 43: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/43.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 44: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/44.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 45: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/45.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 46: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/46.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 47: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/47.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 48: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/48.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 49: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/49.jpg)
Package File Structureapplication/ third_party/ package_name/ config/ helpers/ language/ libraries/ models/
![Page 50: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/50.jpg)
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_name/');
•$this->load->library(‘package_name’);
![Page 51: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/51.jpg)
Remove Package Path
•When finished using a Packages resources.
•When you want to use multiple Packages.
•$this->load->remove_package_path(APPPATH.'third_party/package_name/');
![Page 52: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/52.jpg)
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
![Page 53: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/53.jpg)
// ... 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;
![Page 54: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/54.jpg)
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)
![Page 55: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/55.jpg)
Quick and Dirty Mercurial Tutorial
![Page 56: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/56.jpg)
The Basics
•hg init
•hg pull <url>
•hg pull <constant>
•hg pull <path/to/local/repo>
•hg update
![Page 57: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/57.jpg)
Continued...
•hg diff
•hg add .
•hg add <path/to/file>
•hg commit -m “Commit Message”
•hg push <url>
•hg push <constant>
![Page 58: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/58.jpg)
.hgrc file
•mate $HOME/.hgrc
•[paths]
•ci_master = http://bitbucket.org/ellislab/codeigniter/
![Page 59: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/59.jpg)
Upgrading Tips
![Page 60: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/60.jpg)
Upgrading your Models
•CodeIgniter 1.7.2 Models extend Model
•CodeIgniter 2.0.0 Models extend CI_Model
![Page 61: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/61.jpg)
Lazy mans Model Upgrade
•Create a new Library file: MY_Model.php<?php
class Model extends CI_Model{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 62: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/62.jpg)
Lazy mans Model Upgrade
•Create a new Library file: MY_Model.php<?php
class Model extends CI_Model{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 63: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/63.jpg)
Lazy mans Model Upgrade
•Create a new Library file: MY_Model.php<?php
class Model extends CI_Model{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 64: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/64.jpg)
Lazy mans Model Upgrade
•Create a new Library file: MY_Model.php<?php
class Model extends CI_Model{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 65: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/65.jpg)
Controllers
•Controllers are currently unchanged
•Ellis Lab are evaluating changing the Controller class from Controller to CI_Controller
![Page 66: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/66.jpg)
Lazy mans Controller Upgrade
•Create a new Library file: MY_Controller.php<?php
class Controller extends CI_Controller{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 67: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/67.jpg)
Lazy mans Controller Upgrade
•Create a new Library file: MY_Controller.php<?php
class Controller extends CI_Controller{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 68: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/68.jpg)
Lazy mans Controller Upgrade
•Create a new Library file: MY_Controller.php<?php
class Controller extends CI_Controller{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 69: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/69.jpg)
Lazy mans Controller Upgrade
•Create a new Library file: MY_Controller.php<?php
class Controller extends CI_Controller{ function __construct() { parent::__construct(); } // construct()} // class
?>
![Page 70: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/70.jpg)
Summary
•Plugins, Validation Library & Scaffolding have been removed
•PHP 4 support dropped
•Drivers & Packages
•Model Class renamed
•Mercurial/Bitbucket
![Page 71: CICON2010: Adam Griffiths - CodeIgniter 2](https://reader038.fdocuments.net/reader038/viewer/2022102814/54bf05754a7959db108b46a2/html5/thumbnails/71.jpg)
Q & A
•@adam_griffiths
•Skype: adam-griffiths
•www.adamgriffiths.co.uk
•www.bitbucket.org/adamgriffiths/