Advertisement
Guest User

Mahasiswa_model

a guest
Apr 9th, 2020
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2.     class Mahasiswa_model extends CI_model{
  3.         public function getAllMahasiswa(){
  4.             return $this->db->get('mahasiswa')->result_array();
  5.         }
  6.  
  7.         public function tambahDataMahasiswa(){
  8.             $data = [
  9.                 "nama" => $this->input->post('nama',true),
  10.                 "nrp" => $this->input->post('nrp',true),
  11.                 "email" => $this->input->post('email',true),
  12.                 "jurusan" => $this->input->post('jurusan',true),
  13.                 "kelas" => $this->input->post('kelas',true),
  14.                 "image" => $this->uploadImage()
  15.             ];
  16.             $this->db->insert('mahasiswa',$data);
  17.         }
  18.        
  19.         public function uploadImage(){
  20.             $config['upload_patch']  = './assets/img/profile';
  21.             $config['allowed_types'] = 'jpg|png|jpeg';
  22.             $config['file_name']     = round(1,1000);
  23.             $config['overwrite']     = true;
  24.             $config['max_size']      = 2048; // max 2MB
  25.  
  26.             $this->load->library('upload', $config);
  27.  
  28.             if ($this->upload->do_upload('image')) {
  29.                 return $this->upload->data('file_name');
  30.             }
  31.             return 'no_foto.png';
  32.         }
  33.  
  34.         public function hapusDataMahasiswa($id){
  35.             // $this->db->where('id', $id);  
  36.             $this->db->delete('mahasiswa', ['id' => $id]);
  37.         }
  38.  
  39.         public function getMahasiswaById($id){
  40.             return $this->db->get_where('mahasiswa', ['id' => $id])->row_array();
  41.         }
  42.         public function ubahDataMahasiswa(){
  43.             $data = [
  44.                 "nama" => $this->input->post('nama',true),
  45.                 "nrp" => $this->input->post('nrp',true),
  46.                 "email" => $this->input->post('email',true),
  47.                 "jurusan" => $this->input->post('jurusan',true),
  48.                 "kelas" => $this->input->post('kelas',true)
  49.             ];
  50.             $this->db->where('id', $this->input->post('id') );
  51.             $this->db->update('mahasiswa',$data);
  52.         }
  53.         public function cariDataMahasiswa(){
  54.             $keyword = $this->input->post('keyword');
  55.             $this->db->like('nama', $keyword);
  56.             $this->db->or_like('nrp', $keyword);
  57.             $this->db->or_like('email', $keyword);
  58.             $this->db->or_like('jurusan', $keyword);
  59.             $this->db->or_like('kelas', $keyword);
  60.             return $this->db->get('mahasiswa')->result_array();
  61.         }
  62.     }
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement