Advertisement
eyoku_

Untitled

Jun 16th, 2020
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class ModelKategori extends CI_Model {
  5. var $table = "kategori";
  6. var $primaryKey = "id_kategori";
  7.  
  8. public function insert($data) {
  9. return $this->db->insert($this->table, $data);
  10. }
  11.  
  12. public function insertGetId($data) {
  13. $this->db->insert($this->table, $data);
  14. return $this->db->insert_id();
  15. }
  16.  
  17. public function getAll() {
  18. //hanya mengembalikan data yang is_active = 1
  19. $this->db->where("is_active", 1);
  20. return $this->db->get($this->table)->result();
  21. }
  22.  
  23. public function getByPrimaryKey($id) {
  24. $this->db->where($this->primaryKey, $id);
  25. return $this->db->get($this->table)->row();
  26. }
  27.  
  28. public function update($id, $data) {
  29. $this->db->where($this->primaryKey, $id);
  30. return $this->db->update($this->table, $data);
  31. }
  32.  
  33. // delete data
  34. public function delete($id) {
  35. //hanya mengupdate is_active dari 1 menjadi 0
  36. $this->db->where($this->primaryKey, $id);
  37. return $this->db->update($this->table, array("is_active" => 0));
  38. }
  39.  
  40. public function getJoin(){
  41. $this->db->select('barang.*,kategori.nama_kategori');
  42. $this->db->from('barang');
  43. $this->db->join('kategori','barang');
  44. $query = $this->db->get();
  45. return $query;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement