86 lines
2.5 KiB
PHP
86 lines
2.5 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Kategori extends CI_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model("ModelKategori");
|
|
}
|
|
|
|
function index()
|
|
{
|
|
$kategori = $this->ModelKategori->get_data();
|
|
$data = array(
|
|
'body' => 'Kategori/list',
|
|
'kategori' => $kategori
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function input()
|
|
{
|
|
$kategori = $this->ModelKategori->get_data();
|
|
$data = array(
|
|
'body' => 'Kategori/input',
|
|
'form' => 'Kategori/form',
|
|
'kategori' => $kategori,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function insert()
|
|
{
|
|
$data = array(
|
|
'nama_kategori' => $this->input->post('nama_kategori'),
|
|
);
|
|
if ($this->db->insert("kategori", $data)) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
}
|
|
}
|
|
|
|
function edit(){
|
|
$id = $this->uri->segment(3);
|
|
$kategori = $this->ModelKategori->get_data_edit($id);
|
|
$data = array(
|
|
'body' => 'Kategori/edit',
|
|
'form' => 'Kategori/form',
|
|
'kategori' => $kategori,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
function update()
|
|
{
|
|
$id = $this->uri->segment(3);
|
|
$data = array(
|
|
'nama_kategori' => $this->input->post('nama_kategori'),
|
|
);
|
|
$this->db->where("id_kategori", $id);
|
|
if ($this->db->update("kategori", $data)) {
|
|
// code...
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
}
|
|
}
|
|
|
|
function delete()
|
|
{
|
|
$id = $this->input->post("id_kategori");
|
|
$this->db->where_in("id_kategori", $id);
|
|
if ($this->db->delete("kategori")) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
// code...
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Kategori");
|
|
}
|
|
}
|
|
} |