Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Mahasiswa_model extends CI_model{
- public function getAllMahasiswa(){
- return $this->db->get('mahasiswa')->result_array();
- }
- public function tambahDataMahasiswa(){
- $data = [
- "nama" => $this->input->post('nama',true),
- "nrp" => $this->input->post('nrp',true),
- "email" => $this->input->post('email',true),
- "jurusan" => $this->input->post('jurusan',true),
- "kelas" => $this->input->post('kelas',true),
- "image" => $this->uploadImage()
- ];
- $this->db->insert('mahasiswa',$data);
- }
- public function uploadImage(){
- $config['upload_patch'] = './assets/img/profile';
- $config['allowed_types'] = 'jpg|png|jpeg';
- $config['file_name'] = round(1,1000);
- $config['overwrite'] = true;
- $config['max_size'] = 2048; // max 2MB
- $this->load->library('upload', $config);
- if ($this->upload->do_upload('image')) {
- return $this->upload->data('file_name');
- }
- return 'no_foto.png';
- }
- public function hapusDataMahasiswa($id){
- // $this->db->where('id', $id);
- $this->db->delete('mahasiswa', ['id' => $id]);
- }
- public function getMahasiswaById($id){
- return $this->db->get_where('mahasiswa', ['id' => $id])->row_array();
- }
- public function ubahDataMahasiswa(){
- $data = [
- "nama" => $this->input->post('nama',true),
- "nrp" => $this->input->post('nrp',true),
- "email" => $this->input->post('email',true),
- "jurusan" => $this->input->post('jurusan',true),
- "kelas" => $this->input->post('kelas',true)
- ];
- $this->db->where('id', $this->input->post('id') );
- $this->db->update('mahasiswa',$data);
- }
- public function cariDataMahasiswa(){
- $keyword = $this->input->post('keyword');
- $this->db->like('nama', $keyword);
- $this->db->or_like('nrp', $keyword);
- $this->db->or_like('email', $keyword);
- $this->db->or_like('jurusan', $keyword);
- $this->db->or_like('kelas', $keyword);
- return $this->db->get('mahasiswa')->result_array();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement