Advertisement
Guest User

Untitled

a guest
May 24th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. public function index()
  2. {
  3. $registration = $this->Registration_model->get_all();
  4.  
  5. $data = array(
  6. 'registration_data' => $registration
  7. );
  8.  
  9. $this->load->view('registration/registration_list', $data);
  10.  
  11. }
  12. public function do_upload()
  13. {
  14. $config['upload_path'] = './uploads/pictures/';
  15. $config['allowed_types'] = 'gif|jpg|png';
  16. $config['max_size'] = 10000000;
  17. $config['max_width'] = 10240000;
  18. $config['max_height'] = 76800000;
  19.  
  20. $this->load->library('upload', $config);
  21.  
  22. if ( ! $this->upload->do_upload('Image'))
  23. {
  24. $error = array('error' => $this->upload->display_errors());
  25.  
  26. $this->load->view('registration_form', $error);
  27. }
  28. else
  29. {
  30. $data = array('upload_data' => $this->upload->data());
  31. return $data['upload_data']['file_name'];
  32. }
  33. }
  34. public function read($id)
  35. {
  36. $row = $this->Registration_model->get_by_id($id);
  37. if ($row) {
  38. $data = array(
  39. 'id' => $row->id,
  40. 'firstName' => $row->firstName,
  41. 'lastName' => $row->lastName,
  42. 'gender' => $row->gender,
  43. 'address' => $row->address,
  44. 'dob' => $row->dob,
  45. 'Image' => $row->Image,
  46. );
  47. $this->load->view('registration/registration_read', $data);
  48. } else {
  49. $this->session->set_flashdata('message', 'Record Not Found');
  50. redirect(site_url('registration'));
  51. }
  52. }
  53.  
  54. public function create()
  55. {
  56. $data = array(
  57. 'button' => 'Create',
  58. 'action' => site_url('registration/create_action'),
  59. 'id' => set_value('id'),
  60. 'firstName' => set_value('firstName'),
  61. 'lastName' => set_value('lastName'),
  62. 'gender' => set_value('gender'),
  63. 'address' => set_value('address'),
  64. 'dob' => set_value('dob'),
  65. 'Image' =>set_value('image'),
  66. );
  67. $this->load->view('registration/registration_form', $data);
  68. }
  69.  
  70. public function create_action()
  71. {
  72. $this->_rules();
  73.  
  74. if ($this->form_validation->run() == FALSE) {
  75. $this->create();
  76. } else {
  77. $data = array(
  78. 'firstName' => $this->input->post('firstName',TRUE),
  79. 'lastName' => $this->input->post('lastName',TRUE),
  80. 'gender' => $this->input->post('gender',TRUE),
  81. 'address' => $this->input->post('address',TRUE),
  82. 'dob' => $this->input->post('dob',TRUE),
  83. 'Image' => $this->input->post('Image',TRUE),
  84. );
  85.  
  86. $this->Registration_model->insert($data);
  87. $this->session->set_flashdata('message', 'The New Record was Successfuly Added');
  88. redirect(site_url('registration'));
  89. }
  90. }
  91.  
  92. <div class="form-group">
  93. <label for="varchar">Image <?php echo form_open_multipart('upload/do_upload');?></label>
  94. <input type="file" class="form-control" name="Image" id="Image" height="50" />
  95. <br/>
  96. </div>
  97. <br/>
  98. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  99. <button type="submit" class="btn btn-primary"name="userSubmit"><?php echo $button ?></button>
  100.  
  101. public $table = 'registration';
  102. public $id = 'id';
  103. public $order = 'DESC';
  104.  
  105. function __construct()
  106. {
  107. parent::__construct();
  108. }
  109.  
  110. // get all
  111. function get_all()
  112. {
  113. $this->db->order_by($this->id, $this->order);
  114. return $this->db->get($this->table)->result();
  115. }
  116.  
  117. // get data by id
  118. function get_by_id($id)
  119. {
  120. $this->db->where($this->id, $id);
  121. return $this->db->get($this->table)->row();
  122. }
  123.  
  124. // get total rows
  125. function total_rows($q = NULL) {
  126. $this->db->like('id', $q);
  127. $this->db->or_like('firstName', $q);
  128. $this->db->or_like('lastName', $q);
  129. $this->db->or_like('gender', $q);
  130. $this->db->or_like('address', $q);
  131. $this->db->or_like('dob', $q);
  132. $this->db->or_like('Image', $q);
  133. $this->db->from($this->table);
  134. return $this->db->count_all_results();
  135. }
  136.  
  137. // get data with limit and search
  138. function get_limit_data($limit, $start = 0, $q = NULL) {
  139. $this->db->order_by($this->id, $this->order);
  140. $this->db->like('id', $q);
  141. $this->db->or_like('firstName', $q);
  142. $this->db->or_like('lastName', $q);
  143. $this->db->or_like('gender', $q);
  144. $this->db->or_like('address', $q);
  145. $this->db->or_like('dob', $q);
  146. $this->db->or_like('Image', $q);
  147. $this->db->limit($limit, $start);
  148. return $this->db->get($this->table)->result();
  149. }
  150.  
  151. // insert data
  152. function insert($data)
  153. {
  154. $this->db->insert($this->table, $data);
  155. }
  156.  
  157. // update data
  158. function update($id, $data)
  159. {
  160. $this->db->where($this->id, $id);
  161. $this->db->update($this->table, $data);
  162. }
  163.  
  164. // delete data
  165. function delete($id)
  166. {
  167. $this->db->where($this->id, $id);
  168. $this->db->delete($this->table);
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement