Introduction to CI

Page 1

Introduction to CodeIgniter Ed Finkler coj@funkatron.com • funkatron.com

20070914 1


What is CodeIgniter?

• YAPF

(Yet Another PHP Framework)

Ed Finkler <coj@funkatron.com> 2


Why care about CI? • Battle-tested • Fast • Adaptable

Ed Finkler <coj@funkatron.com> 3


Notable CI features • Fast • Compatible with many environments • Quick to set-up • Plays well with others • Focus on simple solutions • Good docs & community Ed Finkler <coj@funkatron.com> 4


CI structure index.php Loaded by browser Bootstraps everything

system base classes & built-in functionality

application app-specific classes and functionality

Ed Finkler <coj@funkatron.com> 5


CI structure

Ed Finkler <coj@funkatron.com> 6


URL structure domain.com/controller_class/method/data <?php class Search extends Controller { [...] function retrieve($id) { $this->load->database(); [...] } } ?> Ed Finkler <coj@funkatron.com> 7


MVC pattern • Controller Classes • private methods prefixed with “_”

Ed Finkler <coj@funkatron.com> 8


MVC pattern • Views • Plain PHP as templating lang

Ed Finkler <coj@funkatron.com> 9


MVC pattern • Views • Optional template markup

Ed Finkler <coj@funkatron.com> 10


MVC pattern • Models • Optional • ActiveRecord pattern available, not required • Query binding $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; $this->db->query($sql, array(3, 'live', 'Rick'));

Ed Finkler <coj@funkatron.com> 11


Helpers • Procedural funcs, grouped by file • Mostly for views; available in controllers

Ed Finkler <coj@funkatron.com> 12


Plugins • Single procedural function • More extensive functionality than helper

Ed Finkler <coj@funkatron.com> 13


Loading on-demand • $this->load->library|view|helper|plugin|...(‘name’);

• Auto-loading set in config/autoload.php Ed Finkler <coj@funkatron.com> 14


CI security • Not Foolproof (nothing is!) • Limits allowed chars in URI • register_globals “forced off”

Ed Finkler <coj@funkatron.com> 15


CI security • Data only passed via POST or COOKIE • GET query destroyed • Array keys filtered • Auto XSS Filtering (must enable) • Query binding - use it! Ed Finkler <coj@funkatron.com> 16


Extending CI • The CI Way • Creating your own libs • Extend native libs (MY_Email) • As-is, can’t extend/replace controller or database classes

• Replacing native libs • Hooks Ed Finkler <coj@funkatron.com> 17


Extending CI • The “however the hell you want to do it” way

• Just require your libs • Collisions unlikely (not impossible) Ed Finkler <coj@funkatron.com> 18


Example App

• CI + Simplepie + Zend_Json == Web2.0 profit

Ed Finkler <coj@funkatron.com> 19


Danke • codeigniter.com • Slides will be up at funkatron.com shortly

Ed Finkler <coj@funkatron.com> 20


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.