Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
-
Upload
michael-wales -
Category
Technology
-
view
10.169 -
download
1
description
Transcript of Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
CodeIgniterIntroduction to
20 May 2009
What is CodeIgniter?
Open Source PHP Framework
<?php $this->load->view(‘about’);
What is CodeIgniter?
Open Source PHP Framework Free (as in beer / as in rights)
<?php $this->load->view(‘about’);
What is CodeIgniter?
Open Source PHP Framework Free (as in beer / as in rights) The “guts” of ExpressionEngine 2
<?php $this->load->view(‘about’);
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’);
History of CodeIgniter
‘01: Rick Ellis develops pMachine
<?php $this->load->model(‘event’); $data[‘events’] = $this->event->get_all(); $this->load->view(‘history’, $data);
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);
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);
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);
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);
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
CodeIgniter Key Features
Small footprint PHP 4 compatible
<?php $this->load->model(‘feature’); $data[‘features’] = $this->feature->get_all(); $this->load->view(‘features’, $data);
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);
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);
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
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);
“I found CodeIgniter the lightest framework out there and it doesn’t impose too many restrictions.”
Rasmus LerdorfCreator of PHPInfrastructure Architect, Yahoo
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; }}
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; }}
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; }}
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); }}
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); }}
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); }}
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 -->
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 -->
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 -->
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 -->
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