Introduction To CodeIgniter
Introduction To CodeIgniter
Why CodeIgniter?
The CI MVC Model
CI Basics
Running CI out of the box
Making a basic web app
Making a web api
http://www.flickr.com/photos/alternatewords/2332580309/
Why CodeIgniter?
Why not CakePHP or Zend
Framework or Limonade or
Symfony or Solar or Kohana
or Zoop or Yii or Akelos or
PHP on Trax or Prado or
Seagull?
Because you've gotta
pick one, dammit
All of them have value
That being said, CI is…
Easy to understand
Simple
doesn't require advanced OOP
Doesn't force lots of conventions
Plays well with others
Quick to get up and running
Good docs and great community
Backed by invested entity (http://ellislab.com)
CodeIgniter MVC
Implementation
More like
"Passive View Pattern"
Controller
View Model
http://short.ie/5o7eg4
CI application flow
index.php
Routing
http://domain.com/index.php/controller/method/param
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick'));
/**
* Plural
*
* Takes a singular word and makes it plural
*
* @access public
* @param string
* @param bool
* @return str
*/
function plural($str, $force = FALSE)
{
// [...]
}
Plugin
Single procedural function
More extensive functionality than helper
$vals = array(
'word' => 'Random word',
'img_path' => './captcha/',
'img_url' => 'http://example.com/captcha/',
'font_path' => './system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200
);
$cap = create_captcha($vals);
echo $cap['image'];
Script
<h3>{blog_heading}</h3>
{blog_entries}
<h5>{title}</h5>
<p>{body}</p>
Want a heavier template lang? {/blog_entries}
Use one. </body>
</html>
Caching
http://www.flickr.com/photos/canoafurada/395304306/
CI File Layout
front controller
index.php points to system and
application folders
system application
$this->load->{view|library|model|helper|etc}('name');
CI Out of the box
The Welcome App
@funkatron/#cw09
[email protected]