111 lines
3.8 KiB
PHP
111 lines
3.8 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Makanan extends CI_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model("ModelMakanan");
|
|
$this->load->model("ModelKategori");
|
|
}
|
|
|
|
function index()
|
|
{
|
|
$makanan = $this->ModelMakanan->get_data();
|
|
$data = array(
|
|
'body' => 'Makanan/list',
|
|
'makanan' => $makanan
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function input()
|
|
{
|
|
$makanan = $this->ModelMakanan->get_data();
|
|
$kategori = $this->ModelKategori->get_data();
|
|
$data = array(
|
|
'body' => 'Makanan/input',
|
|
'form' => 'Makanan/form',
|
|
'makanan' => $makanan,
|
|
'kategori' => $kategori,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
public function insert()
|
|
{
|
|
$data = array(
|
|
'kategori' => $this->input->post('kategori'),
|
|
'nama_makanan' => $this->input->post('nama_makanan'),
|
|
'kuantitas' => $this->input->post('kuantitas'),
|
|
'besaran' => $this->input->post('besaran'),
|
|
'urt' => $this->input->post('urt'),
|
|
'energi' => $this->input->post('energi'),
|
|
'karbohidrat' => $this->input->post('karbohidrat'),
|
|
'protein' => $this->input->post('protein'),
|
|
'lemak' => $this->input->post('lemak'),
|
|
'besi' => $this->input->post('besi'),
|
|
'vitamina' => $this->input->post('vitamina'),
|
|
'vitaminc' => $this->input->post('vitaminc'),
|
|
);
|
|
if ($this->db->insert("bahan_makanan", $data)) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
}
|
|
}
|
|
|
|
function edit(){
|
|
$id = $this->uri->segment(3);
|
|
$makanan = $this->ModelMakanan->get_data_edit($id);
|
|
$kategori = $this->ModelKategori->get_data();
|
|
$data = array(
|
|
'body' => 'Makanan/edit',
|
|
'form' => 'Makanan/form_edit',
|
|
'makanan' => $makanan,
|
|
'kategori' => $kategori,
|
|
);
|
|
$this->load->view('index', $data);
|
|
}
|
|
function update()
|
|
{
|
|
$id = $this->uri->segment(3);
|
|
$data = array(
|
|
'kategori' => $this->input->post('kategori'),
|
|
'nama_makanan' => $this->input->post('nama_makanan'),
|
|
'kuantitas' => $this->input->post('kuantitas'),
|
|
'besaran' => $this->input->post('besaran'),
|
|
'urt' => $this->input->post('urt'),
|
|
'energi' => $this->input->post('energi'),
|
|
'karbohidrat' => $this->input->post('karbohidrat'),
|
|
'protein' => $this->input->post('protein'),
|
|
'lemak' => $this->input->post('lemak'),
|
|
'besi' => $this->input->post('besi'),
|
|
'vitamina' => $this->input->post('vitamina'),
|
|
'vitaminc' => $this->input->post('vitaminc'),
|
|
);
|
|
$this->db->where("id_makanan", $id);
|
|
if ($this->db->update("bahan_makanan", $data)) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
}
|
|
}
|
|
function delete()
|
|
{
|
|
$id = $this->input->post("id_makanan");
|
|
$this->db->where_in("id_makanan", $id);
|
|
if ($this->db->delete("bahan_makanan")) {
|
|
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
// code...
|
|
} else {
|
|
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
|
|
redirect(base_url() . "Makanan");
|
|
}
|
|
}
|
|
} |