Advertisement
Guest User

Unit.php

a guest
Apr 1st, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class unit extends CI_Controller {
  3.    
  4.     function __construct() {
  5.         parent::__construct();
  6.         check_not_login();
  7.         $this->load->model('unit_m');
  8.     }
  9.    
  10.     public function index(){
  11.         $data['row'] = $this->unit_m->get();
  12.         $this->template->load('template', 'product/unit/unit_data', $data);
  13.     }
  14.  
  15.     public function add() {
  16.         $unit = new stdClass();
  17.         $unit->unit_id = null;
  18.         $unit->name = null;
  19.         $data = array(
  20.             'page' => 'add',
  21.             'row' => $unit
  22.         );
  23.         $this->template->load('template', 'product/unit/unit_form', $data);
  24.     }
  25.  
  26.     public function edit($id) {
  27.         $query = $this->unit_m->get($id);
  28.         if ($query->num_rows() > 0) {
  29.             $unit = $query->row();
  30.             $data = array(
  31.                 'page' => 'edit',
  32.                 'row' => $unit
  33.             );
  34.             $this->template->load('template', 'product/unit/unit_form', $data);
  35.         } else {
  36.             echo "<script>alert('Data tidak ditemukan');";
  37.             echo "window.location='".site_url('unit')."';</script>";
  38.         }
  39.     }
  40.  
  41.     public function process() {
  42.         $post = $this->input->post(null, TRUE);
  43.         if (isset($_POST['add'])) {
  44.             $this->unit_m->add($post);
  45.         } else if (isset($_POST['edit'])) {
  46.             $this->unit_m->edit($post);
  47.         }
  48.        
  49.         if ($this->db->affected_rows() > 0) {
  50.             $this->session->set_flashdata('success', 'Data berhasil disimpan');
  51.         }
  52.         redirect('unit');
  53.     }
  54.  
  55.     public function del($id) {
  56.         $this->unit_m->del($id);
  57.         if ($this->db->affected_rows() > 0) {
  58.             $this->session->set_flashdata('success', 'Data berhasil dihapus');
  59.         }
  60.         redirect('unit');
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement