Who Needs Ruby When You've Got CodeIgniter

3,244 views
3,131 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,244
On SlideShare
0
From Embeds
0
Number of Embeds
1,669
Actions
Shares
0
Downloads
30
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 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

    ×