20
Introduction to CodeIgniter Ed Finkler [email protected] • funkatron.com 20070914 1

Introduction to CI

Embed Size (px)

DESCRIPTION

CI is very powerful

Citation preview

Page 1: Introduction to CI

Introduction to CodeIgniterEd Finkler

[email protected] • funkatron.com

200709141

Page 2: Introduction to CI

Ed Finkler <[email protected]>

What is CodeIgniter?

• YAPF(Yet Another PHP Framework)

2

Page 3: Introduction to CI

Ed Finkler <[email protected]>

Why care about CI?

• Battle-tested

• Fast

• Adaptable

3

Page 4: Introduction to CI

Ed Finkler <[email protected]>

Notable CI features

• Fast

• Compatible with many environments

• Quick to set-up

• Plays well with others

• Focus on simple solutions

• Good docs & community

4

Page 5: Introduction to CI

Ed Finkler <[email protected]>

CI structureindex.php

Loaded by browserBootstraps everything

system

base classes & built-in functionality

application

app-specific classes and functionality

5

Page 7: Introduction to CI

Ed Finkler <[email protected]>

URL structuredomain.com/controller_class/method/data

<?php

class Search extends Controller {

[...]

function retrieve($id)

{

$this->load->database();

[...]

}

}

?>

7

Page 8: Introduction to CI

Ed Finkler <[email protected]>

MVC pattern

• Controller Classes

• private methods prefixed with “_”

8

Page 9: Introduction to CI

Ed Finkler <[email protected]>

MVC pattern

• Views

• Plain PHP as templating lang

9

Page 10: Introduction to CI

Ed Finkler <[email protected]>

MVC pattern

• Views

• Optional template markup

10

Page 11: Introduction to CI

Ed Finkler <[email protected]>

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'));

11

Page 12: Introduction to CI

Ed Finkler <[email protected]>

Helpers

• Procedural funcs, grouped by file

• Mostly for views; available in controllers

12

Page 13: Introduction to CI

Ed Finkler <[email protected]>

Plugins

• Single procedural function

• More extensive functionality than helper

13

Page 14: Introduction to CI

Ed Finkler <[email protected]>

Loading on-demand

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

• Auto-loading set in config/autoload.php

14

Page 15: Introduction to CI

Ed Finkler <[email protected]>

CI security

• Not Foolproof (nothing is!)

• Limits allowed chars in URI

• register_globals “forced off”

15

Page 16: Introduction to CI

Ed Finkler <[email protected]>

CI security

• Data only passed via POST or COOKIE

• GET query destroyed

• Array keys filtered

• Auto XSS Filtering (must enable)

• Query binding - use it!

16

Page 17: Introduction to CI

Ed Finkler <[email protected]>

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

17

Page 18: Introduction to CI

Ed Finkler <[email protected]>

Extending CI

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

• Just require your libs

• Collisions unlikely (not impossible)

18

Page 19: Introduction to CI

Ed Finkler <[email protected]>

Example App

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

19

Page 20: Introduction to CI

Ed Finkler <[email protected]>

Danke

• codeigniter.com

• Slides will be up at funkatron.com shortly

20