SlideShare a Scribd company logo
WHO NEEDS RUBY WHEN YOU’VE
     GOT CODEIGNITER?

           Jamie Rumbelow
           @jamierumbelow




     CodeIgniter Conference, London, 2012
HI, I’M JAMIE
PLUG:
Who Needs Ruby When You've Got CodeIgniter
codeigniterhandbook.com
Who Needs Ruby When You've Got CodeIgniter
SORRY CODEIGNITER,
I’VE GOT ANOTHER GIRL
BUT I STILL ♥ YOU
CODEIGNITER IS MY WIFE,
 RAILS IS MY MISTRESS
RAILS DEVELOPERS?
SMUG.
IN REALITY,
RAILS DEVS ARE RINGOS
“Totally the hot shit”
BOLLOCKS!
RUBY
NOPE!
IT’S ALL ABOUT
THE CONCEPTS
FLEXIBILITY
Who Needs Ruby When You've Got CodeIgniter
OTHER FRAMEWORKS
      COPY
CODEIGNITER
  ADAPTS
WHAT CONCEPTS?
CONVENTION
      >
CONFIGURATION
DON’T
 REPEAT
YOURSELF
A DAY IN THE LIFE
MVC
MVC
IT’S ALL ABOUT
   THE DATA
IT’S ALL ABOUT
*PROCESSING THE DATA
FAT
MODEL
SKINNY
CONTROLLER
MY_Model
public function get($where)
{
  return $this->db->where($where)
             ->get($this->_table);
}
PLURAL TABLE NAME
$this->_table = strtolower(plural(str_replace('_model', '', get_class())));
class User_model extends MY_Model { }
                    Text
class Post_model extends MY_Model { }
class Category_model extends MY_Model { }
OBSERVERS
class User_model extends MY_Model
{
   public $before_create = array( 'hash_password' );
}
foreach ($this->before_create as $method)
{
  $data = call_user_func_array(array($this, $method), array($data));
}
public function hash_password($user)
{
  $user['password'] = sha1($user['password']);

    return $user;
}
SCOPES
return $this;
public function confirmed()
{
  $this->db->where('confirmed', TRUE);
  return $this;
}
$this->user->confirmed()->get_all();
VALIDATION
YOU’RE
DOING
  IT
WRONG
class User_model extends MY_Model
{
   public $validate = array(
      array( 'field' => 'username', 'label' => 'Username',
          'rules' => 'required|max_length[20]|alpha_dash' ),
      array( 'field' => 'password', 'label' => 'Password',
          'rules' => 'required|min_length[8]' ),
      array( 'field' => 'email', 'label' => 'Email',
          'rules' => 'valid_email' )
   );
}
foreach ($data as $key => $value)
{
  $_POST[$key] = $value;
}
$this->form_validation->set_rules($this->validate);

return $this->form_validation->run();
MVC
PRESENTERS
<div id="account">
   <h1>
      <?= $this->bank->get($account->bank_id)->name ?> - <?= $account->title ?>
   </h1>
   <p class="information">
      <strong>Name:</strong> <?php if ($account->name): ?><?= $account->name ?><?php else: ?>N/
A<?php endif; ?><br />
      <strong>Number:</strong> <?php if ($account->number): ?><?= $account->number ?><?php
else: ?>N/A<?php endif; ?><br />
      <strong>Sort Code:</strong> <?php if ($account->sort_code): ?><?= substr($account->sort_code,
0, 2) . "-" . substr($account->sort_code, 2, 2) . "-" . substr($account->sort_code, 4, 2) ?><?php else: ?>N/
A<?php endif; ?>
   </p>
   <p class="balances">
      <strong>Total Balance:</strong> <?php if ($account->total_balance): ?><?= "&pound;" .
number_format($account->total_balance) ?><?php else: ?>N/A<?php endif; ?>
      <strong>Available Balance:</strong> <?php if ($account->available_balance): ?><?= "&pound;" .
number_format($account->available_balance) ?><?php else: ?>N/A<?php endif; ?>
   </p>
   <p class="statements">
      <?php if ($this->statements->count_by('account_id', $account->id)): ?>
          <?= anchor('/statements/' . $account->id, 'View Statements') ?>
      <?php else: ?>
          Statements Not Currently Available
      <?php endif; ?>
   </p>
</div>
<div id="account">
  <h1>
    <?= $account->title() ?>
  </h1>
  <p class="information">
    <strong>Name:</strong> <?= $account->name() ?><br />
    <strong>Number:</strong> <?= $account->number() ?><br />
    <strong>Sort Code:</strong> <?= $account->sort_code() ?>
  </p>
  <p class="balances">
    <strong>Total Balance:</strong> <?= $account->total_balance() ?>
    <strong>Available Balance:</strong> <?= $account->available_balance() ?>
  </p>
  <p class="statements">
    <?= $account->statements_link() ?>
  </p>
</div>
ENCAPSULATE
 THE CLASS
class Account_presenter
{
   public function __construct($account)
   {
     $this->account = $account;
   }
}
public function title()
{
  return get_instance()->bank->get($this->account->bank_id)->name .
       "-" . $this->account->title;
}
GETTING BETTER
public function number()
{
  return $this->account->number ?: "N/A";
}
<div id="account">
   <h1>
      <?= $this->bank->get($account->bank_id)->name ?> - <?= $account->title ?>
   </h1>
   <p class="information">
      <strong>Name:</strong> <?php if ($account->name): ?><?= $account->name ?><?php else: ?>N/
A<?php endif; ?><br />
      <strong>Number:</strong> <?php if ($account->number): ?><?= $account->number ?><?php
else: ?>N/A<?php endif; ?><br />
      <strong>Sort Code:</strong> <?php if ($account->sort_code): ?><?= substr($account->sort_code,
0, 2) . "-" . substr($account->sort_code, 2, 2) . "-" . substr($account->sort_code, 4, 2) ?><?php else: ?>N/
A<?php endif; ?>
   </p>
   <p class="balances">
      <strong>Total Balance:</strong> <?php if ($account->total_balance): ?><?= "&pound;" .
number_format($account->total_balance) ?><?php else: ?>N/A<?php endif; ?>
      <strong>Available Balance:</strong> <?php if ($account->available_balance): ?><?= "&pound;" .
number_format($account->available_balance) ?><?php else: ?>N/A<?php endif; ?>
   </p>
   <p class="statements">
      <?php if ($this->statements->count_by('account_id', $account->id)): ?>
          <?= anchor('/statements/' . $account->id, 'View Statements') ?>
      <?php else: ?>
          Statements Not Currently Available
      <?php endif; ?>
   </p>
</div>
<div id="account">
  <h1>
    <?= $account->title() ?>
  </h1>
  <p class="information">
    <strong>Name:</strong> <?= $account->name() ?><br />
    <strong>Number:</strong> <?= $account->number() ?><br />
    <strong>Sort Code:</strong> <?= $account->sort_code() ?>
  </p>
  <p class="balances">
    <strong>Total Balance:</strong> <?= $account->total_balance() ?>
    <strong>Available Balance:</strong> <?= $account->available_balance() ?>
  </p>
  <p class="statements">
    <?= $account->statements_link() ?>
  </p>
</div>
MVC
AUTOLOADING
application/views/controller/action.php
application/views/controller/action.php
application/views/controller/action.php
application/views/posts/action.php
application/views/posts/index.php
Posts::index();

application/views/posts/index.php
Posts::create();

application/views/posts/create.php
Comments::submit_spam();

application/views/comments/submit_spam.php
MY_Controller
_remap()
$view = strtolower(get_class($this)) . '/' . $method;
$view = strtolower(get_class($this)) . '/' . $method;
$view = strtolower(get_class($this)) . '/' . $method;
$this->load->view($view, $this->data);
public function index()
{
  $this->data['users'] = $this->user->get_all();
  $this->data['title'] = 'All Users';
}
HELP!
$this->load->view('shared/_header', $data);
  $this->load->view('users/all', $data);
$this->load->view('shared/_footer', $data);
$this->data['yield'] = $this->load->view($view, $this->data, TRUE);
$this->load->view('layouts/application', $this->data);
<header>
  <h1>My Application</h1>
</header>

<div id="wrapper">
  <?= $yield ?>
</div>

<footer>
  <p>Copyright &copy; 2012</p>
</footer>
THE END
Jamie Rumbelow
    @jamierumbelow
  jamieonsoftware.com



The CodeIgniter Handbook
codeigniterhandbook.com

More Related Content

KEY
Data::FormValidator Simplified
PPTX
WordPress overloading Gravityforms using hooks, filters and extending classes
PDF
Gravity Forms Hooks & Filters
PDF
CGI::Prototype (NPW 2006)
PPTX
Hacking Your Way To Better Security - Dutch PHP Conference 2016
PDF
Get AngularJS Started!
TXT
Daily notes
PPTX
Security in laravel
Data::FormValidator Simplified
WordPress overloading Gravityforms using hooks, filters and extending classes
Gravity Forms Hooks & Filters
CGI::Prototype (NPW 2006)
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Get AngularJS Started!
Daily notes
Security in laravel

What's hot (20)

PPT
Clever Joomla! Templating Tips and Tricks
PPTX
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
PDF
FamilySearch Reference Client
KEY
Keeping It Simple
PPSX
WordPress Theme Design and Development Workshop - Day 3
PDF
Jqeury ajax plugins
PPTX
Sins Against Drupal 2
PDF
Pagination in PHP
PDF
Add edit delete in Codeigniter in PHP
PDF
Country State City Dropdown in PHP
KEY
Introduction à CoffeeScript pour ParisRB
PPTX
Drupal sins 2016 10-06
PPTX
Magento Dependency Injection
PPTX
Amp Up Your Admin
PPTX
11. CodeIgniter vederea unei singure inregistrari
PDF
Refactoring using Codeception
KEY
WordCamp Denver 2012 - Custom Meta Boxes
PPTX
AngulrJS Overview
PPTX
Building secured wordpress themes and plugins
KEY
JQuery In Rails
Clever Joomla! Templating Tips and Tricks
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
FamilySearch Reference Client
Keeping It Simple
WordPress Theme Design and Development Workshop - Day 3
Jqeury ajax plugins
Sins Against Drupal 2
Pagination in PHP
Add edit delete in Codeigniter in PHP
Country State City Dropdown in PHP
Introduction à CoffeeScript pour ParisRB
Drupal sins 2016 10-06
Magento Dependency Injection
Amp Up Your Admin
11. CodeIgniter vederea unei singure inregistrari
Refactoring using Codeception
WordCamp Denver 2012 - Custom Meta Boxes
AngulrJS Overview
Building secured wordpress themes and plugins
JQuery In Rails
Ad

Viewers also liked (20)

PDF
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (GUJARATI)
DOC
Yiddish Right of REVOLUTION & Political CORRUPTION
PDF
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Turkish)
PDF
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Tajik)
PDF
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Yiddish)
PDF
020915 PUBLIC RELEASE EEOC CHARGE AGAINST 1ST HERITAGE CREDIT (Malay)
PPTX
Unique Styles of Fishing
PDF
GEORGE ZIMMERMAN & EBOLA CRISIS (Urdu)
PDF
03/30/15 FAX EMAIL TO BENNIE THOMPSON-Corrected
PPTX
Programes de formació i inserciò (pfi)
PDF
A study to compare trajectory generation algorithms for automatic bucket fill...
PDF
An Event-driven Operator Model for Dynamic Simulation of Construction Machinery
PDF
021013 adecco email (welsh)
PDF
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (CORSICAN)
PDF
061612 Slideshare Analytic Report Through 06/16/12
PDF
CIPR PRide Awards - Home Counties South
DOC
Hatian Creole Right of REVOLUTION & Political CORRUPTION
PDF
062112 esperanto (supreme court)
DOC
Persian Right of REVOLUTION & Political CORRUPTION
PPTX
Essay Parts
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (GUJARATI)
Yiddish Right of REVOLUTION & Political CORRUPTION
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Turkish)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Tajik)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Yiddish)
020915 PUBLIC RELEASE EEOC CHARGE AGAINST 1ST HERITAGE CREDIT (Malay)
Unique Styles of Fishing
GEORGE ZIMMERMAN & EBOLA CRISIS (Urdu)
03/30/15 FAX EMAIL TO BENNIE THOMPSON-Corrected
Programes de formació i inserciò (pfi)
A study to compare trajectory generation algorithms for automatic bucket fill...
An Event-driven Operator Model for Dynamic Simulation of Construction Machinery
021013 adecco email (welsh)
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (CORSICAN)
061612 Slideshare Analytic Report Through 06/16/12
CIPR PRide Awards - Home Counties South
Hatian Creole Right of REVOLUTION & Political CORRUPTION
062112 esperanto (supreme court)
Persian Right of REVOLUTION & Political CORRUPTION
Essay Parts
Ad

Similar to Who Needs Ruby When You've Got CodeIgniter (20)

PDF
Dealing with Legacy PHP Applications
PDF
Dealing With Legacy PHP Applications
PDF
前后端mvc经验 - webrebuild 2011 session
PPTX
Smarty
PDF
Bag Of Tricks From Iusethis
PDF
Developing for Business
PPT
Os Nixon
PDF
Practical PHP by example Jan Leth-Kjaer
PDF
TDC2016SP - Trilha Developing for Business
PDF
You're Doing it Wrong - WordCamp Orlando
PPTX
Shangz R Brown Presentation
PPTX
Zero to SOLID
PDF
How to Create Login and Registration API in PHP.pdf
KEY
Unit testing zend framework apps
PPTX
Tidy Up Your Code
PDF
Login and Registration form using oop in php
PDF
Improving state of M2 front-end - Magento 2 Community Project
PDF
Building scalable products with WordPress - WordCamp London 2018
PDF
PHPSpec - the only Design Tool you need - 4Developers
PPT
Framework
Dealing with Legacy PHP Applications
Dealing With Legacy PHP Applications
前后端mvc经验 - webrebuild 2011 session
Smarty
Bag Of Tricks From Iusethis
Developing for Business
Os Nixon
Practical PHP by example Jan Leth-Kjaer
TDC2016SP - Trilha Developing for Business
You're Doing it Wrong - WordCamp Orlando
Shangz R Brown Presentation
Zero to SOLID
How to Create Login and Registration API in PHP.pdf
Unit testing zend framework apps
Tidy Up Your Code
Login and Registration form using oop in php
Improving state of M2 front-end - Magento 2 Community Project
Building scalable products with WordPress - WordCamp London 2018
PHPSpec - the only Design Tool you need - 4Developers
Framework

More from ciconf (7)

KEY
CICONF 2012 - Don't Make Me Read Your Mind
PPTX
Chef + AWS + CodeIgniter
KEY
Work Queues
KEY
Pretty Good Practices/Productivity
PDF
Hosting as a Framework
PDF
Zero to Hero in Start-ups
PPTX
How to use ORM
CICONF 2012 - Don't Make Me Read Your Mind
Chef + AWS + CodeIgniter
Work Queues
Pretty Good Practices/Productivity
Hosting as a Framework
Zero to Hero in Start-ups
How to use ORM

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx

Who Needs Ruby When You've Got CodeIgniter

Editor's Notes