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

What's hot (20)

PPT
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
PPTX
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
Atwix
 
PDF
FamilySearch Reference Client
Dallan Quass
 
KEY
Keeping It Simple
Stephanie Leary
 
PPSX
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
PDF
Jqeury ajax plugins
Inbal Geffen
 
PPTX
Sins Against Drupal 2
Aaron Crosman
 
PDF
Pagination in PHP
Vineet Kumar Saini
 
PDF
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
PDF
Country State City Dropdown in PHP
Vineet Kumar Saini
 
KEY
Introduction à CoffeeScript pour ParisRB
jhchabran
 
PPTX
Drupal sins 2016 10-06
Aaron Crosman
 
PPTX
Magento Dependency Injection
Anton Kril
 
PPTX
Amp Up Your Admin
Amanda Giles
 
PPTX
11. CodeIgniter vederea unei singure inregistrari
Razvan Raducanu, PhD
 
PDF
Refactoring using Codeception
Jeroen van Dijk
 
KEY
WordCamp Denver 2012 - Custom Meta Boxes
Jeremy Green
 
PPTX
AngulrJS Overview
Eyal Vardi
 
PPTX
Building secured wordpress themes and plugins
Tikaram Bhandari
 
KEY
JQuery In Rails
Louie Zhao
 
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
Сергей Иващенко - Meet Magento Ukraine - Цены в Magento 2
Atwix
 
FamilySearch Reference Client
Dallan Quass
 
Keeping It Simple
Stephanie Leary
 
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
Jqeury ajax plugins
Inbal Geffen
 
Sins Against Drupal 2
Aaron Crosman
 
Pagination in PHP
Vineet Kumar Saini
 
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
Country State City Dropdown in PHP
Vineet Kumar Saini
 
Introduction à CoffeeScript pour ParisRB
jhchabran
 
Drupal sins 2016 10-06
Aaron Crosman
 
Magento Dependency Injection
Anton Kril
 
Amp Up Your Admin
Amanda Giles
 
11. CodeIgniter vederea unei singure inregistrari
Razvan Raducanu, PhD
 
Refactoring using Codeception
Jeroen van Dijk
 
WordCamp Denver 2012 - Custom Meta Boxes
Jeremy Green
 
AngulrJS Overview
Eyal Vardi
 
Building secured wordpress themes and plugins
Tikaram Bhandari
 
JQuery In Rails
Louie Zhao
 

Viewers also liked (20)

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

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

PDF
Dealing with Legacy PHP Applications
Clinton Dreisbach
 
PDF
Dealing With Legacy PHP Applications
Viget Labs
 
PDF
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
PPTX
Smarty
Aravind Vel
 
PDF
Bag Of Tricks From Iusethis
Marcus Ramberg
 
PDF
Developing for Business
Antonio Spinelli
 
PPT
Os Nixon
oscon2007
 
PDF
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
PDF
TDC2016SP - Trilha Developing for Business
tdc-globalcode
 
PDF
You're Doing it Wrong - WordCamp Orlando
Chris Scott
 
PPTX
Shangz R Brown Presentation
shangbaby
 
PPTX
Zero to SOLID
Vic Metcalfe
 
PDF
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
KEY
Unit testing zend framework apps
Michelangelo van Dam
 
PPTX
Tidy Up Your Code
Abbas Ali
 
PDF
Login and Registration form using oop in php
herat university
 
PDF
Improving state of M2 front-end - Magento 2 Community Project
Bartek Igielski
 
PDF
Building scalable products with WordPress - WordCamp London 2018
Elliot Taylor
 
PDF
PHPSpec - the only Design Tool you need - 4Developers
Kacper Gunia
 
PPT
Framework
Nguyen Linh
 
Dealing with Legacy PHP Applications
Clinton Dreisbach
 
Dealing With Legacy PHP Applications
Viget Labs
 
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
Smarty
Aravind Vel
 
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Developing for Business
Antonio Spinelli
 
Os Nixon
oscon2007
 
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
TDC2016SP - Trilha Developing for Business
tdc-globalcode
 
You're Doing it Wrong - WordCamp Orlando
Chris Scott
 
Shangz R Brown Presentation
shangbaby
 
Zero to SOLID
Vic Metcalfe
 
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
Unit testing zend framework apps
Michelangelo van Dam
 
Tidy Up Your Code
Abbas Ali
 
Login and Registration form using oop in php
herat university
 
Improving state of M2 front-end - Magento 2 Community Project
Bartek Igielski
 
Building scalable products with WordPress - WordCamp London 2018
Elliot Taylor
 
PHPSpec - the only Design Tool you need - 4Developers
Kacper Gunia
 
Framework
Nguyen Linh
 
Ad

More from ciconf (7)

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

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 

Who Needs Ruby When You've Got CodeIgniter

Editor's Notes