Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index()
- {
- $registration = $this->Registration_model->get_all();
- $data = array(
- 'registration_data' => $registration
- );
- $this->load->view('registration/registration_list', $data);
- }
- public function do_upload()
- {
- $config['upload_path'] = './uploads/pictures/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = 10000000;
- $config['max_width'] = 10240000;
- $config['max_height'] = 76800000;
- $this->load->library('upload', $config);
- if ( ! $this->upload->do_upload('Image'))
- {
- $error = array('error' => $this->upload->display_errors());
- $this->load->view('registration_form', $error);
- }
- else
- {
- $data = array('upload_data' => $this->upload->data());
- return $data['upload_data']['file_name'];
- }
- }
- public function read($id)
- {
- $row = $this->Registration_model->get_by_id($id);
- if ($row) {
- $data = array(
- 'id' => $row->id,
- 'firstName' => $row->firstName,
- 'lastName' => $row->lastName,
- 'gender' => $row->gender,
- 'address' => $row->address,
- 'dob' => $row->dob,
- 'Image' => $row->Image,
- );
- $this->load->view('registration/registration_read', $data);
- } else {
- $this->session->set_flashdata('message', 'Record Not Found');
- redirect(site_url('registration'));
- }
- }
- public function create()
- {
- $data = array(
- 'button' => 'Create',
- 'action' => site_url('registration/create_action'),
- 'id' => set_value('id'),
- 'firstName' => set_value('firstName'),
- 'lastName' => set_value('lastName'),
- 'gender' => set_value('gender'),
- 'address' => set_value('address'),
- 'dob' => set_value('dob'),
- 'Image' =>set_value('image'),
- );
- $this->load->view('registration/registration_form', $data);
- }
- public function create_action()
- {
- $this->_rules();
- if ($this->form_validation->run() == FALSE) {
- $this->create();
- } else {
- $data = array(
- 'firstName' => $this->input->post('firstName',TRUE),
- 'lastName' => $this->input->post('lastName',TRUE),
- 'gender' => $this->input->post('gender',TRUE),
- 'address' => $this->input->post('address',TRUE),
- 'dob' => $this->input->post('dob',TRUE),
- 'Image' => $this->input->post('Image',TRUE),
- );
- $this->Registration_model->insert($data);
- $this->session->set_flashdata('message', 'The New Record was Successfuly Added');
- redirect(site_url('registration'));
- }
- }
- <div class="form-group">
- <label for="varchar">Image <?php echo form_open_multipart('upload/do_upload');?></label>
- <input type="file" class="form-control" name="Image" id="Image" height="50" />
- <br/>
- </div>
- <br/>
- <input type="hidden" name="id" value="<?php echo $id; ?>" />
- <button type="submit" class="btn btn-primary"name="userSubmit"><?php echo $button ?></button>
- public $table = 'registration';
- public $id = 'id';
- public $order = 'DESC';
- function __construct()
- {
- parent::__construct();
- }
- // get all
- function get_all()
- {
- $this->db->order_by($this->id, $this->order);
- return $this->db->get($this->table)->result();
- }
- // get data by id
- function get_by_id($id)
- {
- $this->db->where($this->id, $id);
- return $this->db->get($this->table)->row();
- }
- // get total rows
- function total_rows($q = NULL) {
- $this->db->like('id', $q);
- $this->db->or_like('firstName', $q);
- $this->db->or_like('lastName', $q);
- $this->db->or_like('gender', $q);
- $this->db->or_like('address', $q);
- $this->db->or_like('dob', $q);
- $this->db->or_like('Image', $q);
- $this->db->from($this->table);
- return $this->db->count_all_results();
- }
- // get data with limit and search
- function get_limit_data($limit, $start = 0, $q = NULL) {
- $this->db->order_by($this->id, $this->order);
- $this->db->like('id', $q);
- $this->db->or_like('firstName', $q);
- $this->db->or_like('lastName', $q);
- $this->db->or_like('gender', $q);
- $this->db->or_like('address', $q);
- $this->db->or_like('dob', $q);
- $this->db->or_like('Image', $q);
- $this->db->limit($limit, $start);
- return $this->db->get($this->table)->result();
- }
- // insert data
- function insert($data)
- {
- $this->db->insert($this->table, $data);
- }
- // update data
- function update($id, $data)
- {
- $this->db->where($this->id, $id);
- $this->db->update($this->table, $data);
- }
- // delete data
- function delete($id)
- {
- $this->db->where($this->id, $id);
- $this->db->delete($this->table);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement