Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
WHO NEEDS RUBY WHEN YOU’VE     GOT CODEIGNITER?           Jamie Rumbelow           @jamierumbelow     CodeIgniter Conferen...
HI, I’M JAMIE
PLUG:
codeigniterhandbook.com
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 ABOUTTHE CONCEPTS
FLEXIBILITY
OTHER FRAMEWORKS      COPY
CODEIGNITER  ADAPTS
WHAT CONCEPTS?
CONVENTION      >CONFIGURATION
DON’T REPEATYOURSELF
A DAY IN THE LIFE
MVC
MVC
IT’S ALL ABOUT   THE DATA
IT’S ALL ABOUT*PROCESSING THE DATA
FATMODELSKINNYCONTROLLER
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 { }                    Textclass Post_model extends MY_Model { }class Category_model ext...
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’REDOING  ITWRONG
class User_model extends MY_Model{   public $validate = array(      array( field => username, label => Username,          r...
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 clas...
<div id="account">  <h1>    <?= $account->title() ?>  </h1>  <p class="information">    <strong>Name:</strong> <?= $accoun...
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->ti...
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 clas...
<div id="account">  <h1>    <?= $account->title() ?>  </h1>  <p class="information">    <strong>Name:</strong> <?= $accoun...
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></f...
THE END
Jamie Rumbelow    @jamierumbelow  jamieonsoftware.comThe CodeIgniter Handbookcodeigniterhandbook.com
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
Upcoming SlideShare
Loading in …5
×

Who Needs Ruby When You've Got CodeIgniter

3,348 views

Published on

Published in: Technology
  • Be the first to comment

Who Needs Ruby When You've Got CodeIgniter

  1. 1. WHO NEEDS RUBY WHEN YOU’VE GOT CODEIGNITER? Jamie Rumbelow @jamierumbelow CodeIgniter Conference, London, 2012
  2. 2. HI, I’M JAMIE
  3. 3. PLUG:
  4. 4. codeigniterhandbook.com
  5. 5. SORRY CODEIGNITER,I’VE GOT ANOTHER GIRL
  6. 6. BUT I STILL ♥ YOU
  7. 7. CODEIGNITER IS MY WIFE, RAILS IS MY MISTRESS
  8. 8. RAILS DEVELOPERS?
  9. 9. SMUG.
  10. 10. IN REALITY,RAILS DEVS ARE RINGOS
  11. 11. “Totally the hot shit”
  12. 12. BOLLOCKS!
  13. 13. RUBY
  14. 14. NOPE!
  15. 15. IT’S ALL ABOUTTHE CONCEPTS
  16. 16. FLEXIBILITY
  17. 17. OTHER FRAMEWORKS COPY
  18. 18. CODEIGNITER ADAPTS
  19. 19. WHAT CONCEPTS?
  20. 20. CONVENTION >CONFIGURATION
  21. 21. DON’T REPEATYOURSELF
  22. 22. A DAY IN THE LIFE
  23. 23. MVC
  24. 24. MVC
  25. 25. IT’S ALL ABOUT THE DATA
  26. 26. IT’S ALL ABOUT*PROCESSING THE DATA
  27. 27. FATMODELSKINNYCONTROLLER
  28. 28. MY_Model
  29. 29. public function get($where){ return $this->db->where($where) ->get($this->_table);}
  30. 30. PLURAL TABLE NAME
  31. 31. $this->_table = strtolower(plural(str_replace(_model, , get_class())));
  32. 32. class User_model extends MY_Model { } Textclass Post_model extends MY_Model { }class Category_model extends MY_Model { }
  33. 33. OBSERVERS
  34. 34. class User_model extends MY_Model{ public $before_create = array( hash_password );}
  35. 35. foreach ($this->before_create as $method){ $data = call_user_func_array(array($this, $method), array($data));}
  36. 36. public function hash_password($user){ $user[password] = sha1($user[password]); return $user;}
  37. 37. SCOPES
  38. 38. return $this;
  39. 39. public function confirmed(){ $this->db->where(confirmed, TRUE); return $this;}
  40. 40. $this->user->confirmed()->get_all();
  41. 41. VALIDATION
  42. 42. YOU’REDOING ITWRONG
  43. 43. 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 ) );}
  44. 44. foreach ($data as $key => $value){ $_POST[$key] = $value;}
  45. 45. $this->form_validation->set_rules($this->validate);return $this->form_validation->run();
  46. 46. MVC
  47. 47. PRESENTERS
  48. 48. <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 ?><?phpelse: ?>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>
  49. 49. <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>
  50. 50. ENCAPSULATE THE CLASS
  51. 51. class Account_presenter{ public function __construct($account) { $this->account = $account; }}
  52. 52. public function title(){ return get_instance()->bank->get($this->account->bank_id)->name . "-" . $this->account->title;}
  53. 53. GETTING BETTER
  54. 54. public function number(){ return $this->account->number ?: "N/A";}
  55. 55. <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 ?><?phpelse: ?>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>
  56. 56. <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>
  57. 57. MVC
  58. 58. AUTOLOADING
  59. 59. application/views/controller/action.php
  60. 60. application/views/controller/action.php
  61. 61. application/views/controller/action.php
  62. 62. application/views/posts/action.php
  63. 63. application/views/posts/index.php
  64. 64. Posts::index();application/views/posts/index.php
  65. 65. Posts::create();application/views/posts/create.php
  66. 66. Comments::submit_spam();application/views/comments/submit_spam.php
  67. 67. MY_Controller
  68. 68. _remap()
  69. 69. $view = strtolower(get_class($this)) . / . $method;
  70. 70. $view = strtolower(get_class($this)) . / . $method;
  71. 71. $view = strtolower(get_class($this)) . / . $method;
  72. 72. $this->load->view($view, $this->data);
  73. 73. public function index(){ $this->data[users] = $this->user->get_all(); $this->data[title] = All Users;}
  74. 74. HELP!
  75. 75. $this->load->view(shared/_header, $data); $this->load->view(users/all, $data);$this->load->view(shared/_footer, $data);
  76. 76. $this->data[yield] = $this->load->view($view, $this->data, TRUE);$this->load->view(layouts/application, $this->data);
  77. 77. <header> <h1>My Application</h1></header><div id="wrapper"> <?= $yield ?></div><footer> <p>Copyright &copy; 2012</p></footer>
  78. 78. THE END
  79. 79. Jamie Rumbelow @jamierumbelow jamieonsoftware.comThe CodeIgniter Handbookcodeigniterhandbook.com

×