codeigniter_test2/application/controllers/barang_controller.php
2020-01-02 23:07:40 +07:00

65 lines
1.7 KiB
PHP

<?php
class barang_controller extends CI_Controller{
function __Construct()
{
parent ::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('barang_model');
}
function barang()
{
if( $this->session->userdata('isLoggedIn') ) {
$this->load->model('barang_model');
$data['judul'] = 'Tampil barang';
$data['daftar_barang'] = $this->barang_model->get_barang_all();
$this->load->view('HalamanUtama', $data);
} else {
redirect('user_controller/login');
}
}
function add_Barang()
{
$data['judul'] = 'Tambah Barang';
$this->load->view('add_barang',$data);
}
function simpan_barang()
{
$this->barang_model->simpan_barang();
redirect('barang_controller/barang','refresh');
}
function edit($id)
{
$data['judul']='Update Barang';
$data['edit']=$this->barang_model->update_barang($id);
$this->load->view('edit_barang', $data);
}
function simpan_update_barang()
{
$id = $this->input->post('id');
$nama = $this->input->post('nama_barang');
$harga = $this->input->post('harga');
$data['judul'] = 'Update Data Codeigniter';
$this->load->model('user_model');
$data['edit'] = $this->barang_model->simpan_update_barang($id, $nama, $harga);
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Succesfully Updated')
</SCRIPT>");
redirect('barang_controller/barang','refresh');
}
function delete($id)
{
$id = $this->barang_model->delete_barang($id);
redirect('barang_controller/barang');
}
}