Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

29
CodeIgniter Introduction to 20 May 2009

description

I gave this presentation at the monthly RefreshAugusta meeting on 20 May 2009 at The Well in Downtown Augusta.

Transcript of Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Page 1: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniterIntroduction to

20 May 2009

Page 2: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

What is CodeIgniter?

Open Source PHP Framework

<?php $this->load->view(‘about’);

Page 3: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

What is CodeIgniter?

Open Source PHP Framework Free (as in beer / as in rights)

<?php $this->load->view(‘about’);

Page 4: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

What is CodeIgniter?

Open Source PHP Framework Free (as in beer / as in rights) The “guts” of ExpressionEngine 2

<?php $this->load->view(‘about’);

Page 5: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

What is CodeIgniter?

Open Source PHP Framework Free (as in beer / as in rights) The “guts” of ExpressionEngine 2 Backed by bootstrapped company

<?php $this->load->view(‘about’);

Page 6: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

History of CodeIgniter

‘01: Rick Ellis develops pMachine

<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);

Page 7: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

History of CodeIgniter

‘01: Rick Ellis develops pMachine ‘02: pMachine publicly released

<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);

Page 8: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

History of CodeIgniter

‘01: Rick Ellis develops pMachine ‘02: pMachine publicly released ‘04: ExpressionEngine released

<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);

Page 9: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

History of CodeIgniter

‘01: Rick Ellis develops pMachine ‘02: pMachine publicly released ‘04: ExpressionEngine released ‘06: CodeIgniter released

<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);

Page 10: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

History of CodeIgniter

‘01: Rick Ellis develops pMachine ‘02: pMachine publicly released ‘04: ExpressionEngine released ‘06: CodeIgniter released ’08: ExpressionEngine 2 demoed at SXSW

<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);

Page 11: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

2.9x

10.5x

Page 12: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint PHP 4 compatible

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

Page 13: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint PHP 4 compatible Database abstraction layer

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

Page 14: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint PHP 4 compatible Database abstraction layer Global XSS filtering

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

Page 15: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint PHP 4 compatible Database abstraction layer Global XSS filtering SEO friendly URLs

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

example.com/controller/method/var1/var2

Page 16: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

CodeIgniter Key Features

Small footprint PHP 4 compatible Database abstraction layer Global XSS filtering SEO friendly URLs Infinitely extensible

<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);

Page 17: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

“I found CodeIgniter the lightest framework out there and it doesn’t impose too many restrictions.”

Rasmus LerdorfCreator of PHPInfrastructure Architect, Yahoo

Page 18: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Model (models/post.php)

<?phpclass Post extends Model { function Post() { parent::Model(); }

function get_all() { $this->db->order_by(‘postdate’, ‘DESC’); $query = $this->db->get(‘posts’, 10, 0); if ($query->num_rows() > 0) { return $query->result(); } return FALSE; }}

Page 19: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Model (models/post.php)

<?phpclass Post extends Model { function Post() { parent::Model(); }

function get_all() { $this->db->order_by(‘postdate’, ‘DESC’); $query = $this->db->get(‘posts’, 10, 0); if ($query->num_rows() > 0) { return $query->result(); } return FALSE; }}

Page 20: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Model (models/post.php)

<?phpclass Post extends Model { function Post() { parent::Model(); }

function get_all() { $this->db->order_by(‘postdate’, ‘DESC’); $query = $this->db->get(‘posts’, 10, 0); if ($query->num_rows() > 0) { return $query->result(); } return FALSE; }}

Page 21: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Controller (controllers/posts.php)

<?phpclass Posts extends Controller { function Posts() { parent::Controller(); }

function index() { $this->load->model(‘post’); $data[‘posts’] = $this->post->get_all(); $this->load->view(‘home’, $data); }}

Page 22: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Controller (controllers/posts.php)

<?phpclass Posts extends Controller { function Posts() { parent::Controller(); }

function index() { $this->load->model(‘post’); $data[‘posts’] = $this->post->get_all(); $this->load->view(‘home’, $data); }}

Page 23: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Controller (controllers/posts.php)

<?phpclass Posts extends Controller { function Posts() { parent::Controller(); }

function index() { $this->load->model(‘post’); $data[‘posts’] = $this->post->get_all(); $this->load->view(‘home’, $data); }}

Page 24: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

View (views/home.php)

<!-– html, head, body tag --><?php foreach($posts as $p): ?> <div class=“post”> <h2><?php echo $p->title; ?></h2> <div class=“excerpt”> <?php echo $p->excerpt; ?> </div> <p><?php echo anchor($p->id, ‘Read More’); ?

></p> </div><?php endforeach; ?><!-- /body, /head, /html tags -->

Page 25: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

View (views/home.php)

<!-– html, head, body tag --><?php foreach($posts as $p): ?> <div class=“post”> <h2><?php echo $p->title; ?></h2> <div class=“excerpt”> <?php echo $p->excerpt; ?> </div> <p><?php echo anchor($p->id, ‘Read More’); ?

></p> </div><?php endforeach; ?><!-- /body, /head, /html tags -->

Page 26: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

View (views/home.php)

<!-– html, head, body tag --><?php foreach($posts as $p): ?> <div class=“post”> <h2><?php echo $p->title; ?></h2> <div class=“excerpt”> <?php echo $p->excerpt; ?> </div> <p><?php echo anchor($p->id, ‘Read More’); ?

></p> </div><?php endforeach; ?><!-- /body, /head, /html tags -->

Page 27: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

View (views/home.php)

<!-– html, head, body tag --><?php foreach($posts as $p): ?> <div class=“post”> <h2><?php echo $p->title; ?></h2> <div class=“excerpt”> <?php echo $p->excerpt; ?> </div> <p><?php echo anchor($p->id, ‘Read More’); ?

></p> </div><?php endforeach; ?><!-- /body, /head, /html tags -->

Page 28: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

View (views/home.php)

<!-– html, head, body tag --><?php foreach($posts as $p): ?> <div class=“post”> <h2><?php echo $p->title; ?></h2> <div class=“excerpt”> <?php echo $p->excerpt; ?> </div> <p><?php echo anchor($p->slug, ‘Read More’); ?

></p> </div><?php endforeach; ?><!-- /body, /head, /html tags -->

example.com/refreshaugust-may-2009

Page 29: Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)

Questions?

michaelwales.comTwitter: @walesmd

[email protected]