SHARE
TWEET

Untitled

riandaka_ Dec 3rd, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit ('No direct script access allowed');
  3.  
  4. class Workbook extends CI_Controller
  5. {  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->load->model("workbook_model"); //load model workbook
  10.         $this->load->library('form_validation'); //load library form validation
  11.     }
  12.  
  13.     public function index()
  14.     {
  15.         $data["workbook"] = $this->workbook_model->getAll(); //ambil data dari model
  16.         $this->load->view("admin/workbook/list_workbook", $data); //load view data model ke workbook
  17.     }
  18.  
  19.     public function add()
  20.     {
  21.         $workbook = $this->workbook_model; //objek model
  22.         $validation = $this->form_validation; //objek form validation
  23.         $validation->set_rules($workbook->rules()); //terapkan rules
  24.        
  25.         if ($validation->run()){
  26.             $workbook->save();
  27.             $this->session->set_flashdata('Sukses', 'Data Anda Berhasil Disimpan'); //pesan berhasil
  28.         }
  29.  
  30.         $data["workbook"] = $this->workbook_model->get_data_stage();
  31.         $this->load->view("admin/workbook/new_form", $data); //load isi form workbook
  32.     }
  33.  
  34.     public function edit($id=null)
  35.     {
  36.         if(!isset($id)) redirect('admin/workbook/list_workbook');
  37.  
  38.         $workbook = $this->workbook_model;
  39.         $validation = $this->form_validation;
  40.         $validation->set_rules($workbook->rules());
  41.  
  42.         if ($validation->run()){
  43.             $workbook->update();
  44.             $this->session->set_flashdata('success', 'Data Anda Berhasil Diupdate'); //pesan berhasil
  45.         }
  46.  
  47.         $data["workbook"] = $workbook->getById($id); //mengambil data berdasarkan id
  48.         if (!$data["workbook"]) show_404();// jika tidak ada show error
  49.         $this->load->view("admin/workbook/edit_form", $data); //load edit form workbook
  50.     }
  51.  
  52.     public function delete($id=null)
  53.     {
  54.         if (!isset($id)) show_404();
  55.  
  56.         if ($this->workbook_model->delete($id)){
  57.             redirect('index.php/admin/workbook');
  58.         }
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top