Advertisement
Guest User

Untitled

a guest
May 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 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="date">Dob <?php echo form_error('dob') ?></label>
  94. <input type="text" class="form-control" name="dob" id="dob" placeholder="Dob" value="<?php echo $dob; ?>" />
  95. </div>
  96. <div class="form-group">
  97. <label for="varchar">Image <?php echo form_open_multipart('upload/do_upload');?></label>
  98. <input type="file" class="form-control" name="Image" id="Image" height="50" />
  99. <br/>
  100. </div>
  101. <br/>
  102. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  103. <button type="submit" class="btn btn-primary"name="userSubmit"><?php echo $button ?></button>
  104.  
  105.  
  106. class Registration_model extends CI_Model
  107. {
  108.  
  109. public $table = 'registration';
  110. public $id = 'id';
  111. public $order = 'DESC';
  112.  
  113. function __construct()
  114. {
  115. parent::__construct();
  116. }
  117.  
  118. // get all
  119. function get_all()
  120. {
  121. $this->db->order_by($this->id, $this->order);
  122. return $this->db->get($this->table)->result();
  123. }
  124.  
  125. // get data by id
  126. function get_by_id($id)
  127. {
  128. $this->db->where($this->id, $id);
  129. return $this->db->get($this->table)->row();
  130. }
  131.  
  132. // get total rows
  133. function total_rows($q = NULL) {
  134. $this->db->like('id', $q);
  135. $this->db->or_like('firstName', $q);
  136. $this->db->or_like('lastName', $q);
  137. $this->db->or_like('gender', $q);
  138. $this->db->or_like('address', $q);
  139. $this->db->or_like('dob', $q);
  140. $this->db->or_like('Image', $q);
  141. $this->db->from($this->table);
  142. return $this->db->count_all_results();
  143. }
  144.  
  145. // get data with limit and search
  146. function get_limit_data($limit, $start = 0, $q = NULL) {
  147. $this->db->order_by($this->id, $this->order);
  148. $this->db->like('id', $q);
  149. $this->db->or_like('firstName', $q);
  150. $this->db->or_like('lastName', $q);
  151. $this->db->or_like('gender', $q);
  152. $this->db->or_like('address', $q);
  153. $this->db->or_like('dob', $q);
  154. $this->db->or_like('Image', $q);
  155. $this->db->limit($limit, $start);
  156. return $this->db->get($this->table)->result();
  157. }
  158.  
  159. // insert data
  160. function insert($data)
  161. {
  162. $this->db->insert($this->table, $data);
  163. }
  164.  
  165. // update data
  166. function update($id, $data)
  167. {
  168. $this->db->where($this->id, $id);
  169. $this->db->update($this->table, $data);
  170. }
  171.  
  172. // delete data
  173. function delete($id)
  174. {
  175. $this->db->where($this->id, $id);
  176. $this->db->delete($this->table);
  177. }
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement