CI sample models / controlers structure


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2. |MODELS
  3. ||usersdb.php
  4. |CONTROLLERS
  5. ||users.php
  6.  
  7. the model and controller can then have different methods eg, add a user, remove a user, view all users etc.
  8. */
  9.  
  10.  
  11. class Usersdb extends Model
  12. {
  13. /**
  14.   * The Initialisation method
  15.   */
  16.  
  17. function Usersdb()
  18. {
  19. parent::Model();
  20. }
  21. function add($name)
  22. {
  23. ...
  24. }
  25. function delete($userid)
  26. {
  27. ...
  28. }
  29. }
  30.  
  31.  
  32.  
  33. class User extends Controller {
  34.  
  35. function User()
  36. {
  37. parent::Controller();
  38. $this->load->model('usersdb');
  39. $this->load->scaffolding('users');
  40. }
  41. function add()
  42. {
  43. $name = 'test';
  44. $res = $this->usersdb->add($name);
  45. $data['res'] = $res;
  46. $this->load->view('users/user_add_v', $data);
  47. }
  48. function delete($id)
  49. {
  50. $res = $this->usersdb->delete($id);
  51. $data['res'] = $res;
  52. $this->load->view('users/user_remove_v', $data);
  53. }
  54.  
  55.  
  56.  
  57.  
  58. /*
  59. so to add a user you would use the URL
  60.  
  61. whatever.com/codeigniter/index.php/user/add
  62. */

URL: http://codeigniter.com/forums/viewthread/76840/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.