fadilzteria

Biodata_model

Dec 12th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class Biodata_model extends CI_Model
  4. {
  5.     private $_table = "calon_siswa";
  6.  
  7.     public $biodata_id;
  8.     public $nama;
  9.     public $alamat;
  10.     public $jenis_kelamin;
  11.     public $agama;
  12.     public $sekolah_asal;
  13.     public $sekolah_tujuan;
  14.  
  15.     public function rules()
  16.     {
  17.         return [
  18.             ['field' => 'nama',
  19.             'label' => 'Nama',
  20.             'rules' => 'required'],
  21.  
  22.             ['field' => 'alamat',
  23.             'label' => 'Alamat',
  24.             'rules' => 'required'],
  25.            
  26.             ['field' => 'jenis_kelamin',
  27.             'label' => 'Jenis Kelamin',
  28.             'rules' => 'required'],
  29.  
  30.             ['field' => 'agama',
  31.             'label' => 'Agama',
  32.             'rules' => 'required'],
  33.  
  34.             ['field' => 'sekolah_asal',
  35.             'label' => 'Sekolah Asal',
  36.             'rules' => 'required'],
  37.  
  38.             ['field' => 'sekolah_tujuan',
  39.             'label' => 'Sekolah Tujuan',
  40.             'rules' => 'required']
  41.         ];
  42.     }
  43.  
  44.     public function getAll()
  45.     {
  46.         return $this->db->get($this->_table)->result();
  47.     }
  48.    
  49.     public function getById($id)
  50.     {
  51.         return $this->db->get_where($this->_table, ["biodata_id" => $id])->row();
  52.     }
  53.  
  54.     public function save()
  55.     {
  56.         $post = $this->input->post();
  57.         $this->biodata_id = uniqid();
  58.         $this->nama = $post["nama"];
  59.         $this->alamat = $post["alamat"];
  60.         $this->jenis_kelamin = $post["jenis_kelamin"];
  61.         $this->agama = $post["agama"];
  62.         $this->sekolah_asal = $post["sekolah_asal"];
  63.         $this->sekolah_tujuan = $post["sekolah_tujuan"];
  64.         $this->db->insert($this->_table, $this);
  65.     }
  66.  
  67.     public function update()
  68.     {
  69.         $post = $this->input->post();
  70.         $this->biodata_id = $post["biodata_id"];
  71.         $this->nama = $post["nama"];
  72.         $this->alamat = $post["alamat"];
  73.         $this->jenis_kelamin = $post["jenis_kelamin"];
  74.         $this->agama = $post["agama"];
  75.         $this->sekolah_asal = $post["sekolah_asal"];
  76.         $this->sekolah_tujuan = $post["sekolah_tujuan"];
  77.         $this->db->update($this->_table, $this, array('biodata_id' => $post['biodata_id']));
  78.     }
  79.  
  80.     public function delete($id)
  81.     {
  82.         return $this->db->delete($this->_table, array("biodata_id" => $id));
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment