Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.74 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class Barang extends CI_Controller {
  4.    public function __construct()
  5.    {
  6.         parent::__construct();
  7.         $this->load->model("barangCRUD_model");
  8.         $this->load->library('form_validation');
  9.         $this->load->library('pdf');
  10.         $this->load->model("user_model");
  11.         if($this->user_model->isNotLogin()) redirect(site_url('admin/login'));
  12.     }
  13.  
  14.     public function index()
  15.     {
  16.         // load view admin/overview.php
  17.         $data["barangs"] = $this->barangCRUD_model->getAll();
  18.         $this->load->view("admin/barang",$data);
  19.     }
  20.  
  21.     public function add()
  22.     {
  23.         $this->load->view("admin/new_barang");
  24.     }
  25.  
  26.     public function save()
  27.     {
  28.         $this->barangCRUD_model->save();
  29.         $this->session->set_flashdata('success', 'Data berhasil disimpan');
  30.         return redirect(site_url('admin/barang'));
  31.     }
  32.  
  33.     public function upd(){
  34.         $this->barangCRUD_model->update();
  35.         $data["barangs"] = $this->barangCRUD_model->getAll();
  36.         $this->session->set_flashdata('success', 'Barang Berhasil Diedit');
  37.         return redirect(site_url('admin/barang'));
  38.     }
  39.  
  40.     public function edit($id = null)
  41.     {
  42.         if (!isset($id)) redirect('admin/barang');
  43.        
  44.         $barang = $this->barangCRUD_model;
  45.  
  46.         $data["barangs"] = $barang->getById($id);
  47.         if (!$data["barangs"]) show_404();
  48.        
  49.         $this->load->view("admin/edit_barang", $data);
  50.     }
  51.    
  52.  
  53.     public function delete($id=null)
  54.     {
  55.         if (!isset($id)) show_404();
  56.        
  57.         if ($this->barangCRUD_model->delete($id)) {
  58.             $this->session->set_flashdata('success', 'Barang berhasil dihapus');
  59.             redirect(site_url('admin/barang'));
  60.         }
  61.     }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement