73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Product extends CI_Controller {
|
|
private $_tpl_path;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->_tpl_path = 'admin/' . config_item('admin_template') . '/';
|
|
$this->load->model("m_product");
|
|
$this->load->library('form_validation');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$product = $this->m_product;
|
|
|
|
$data = array(
|
|
'tpl_path' => $this->_tpl_path,
|
|
'products' => $product->getAll()
|
|
);
|
|
$this->load->view($this->_tpl_path . 'product/list',$data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$product = $this->m_product;
|
|
$validation = $this->form_validation;
|
|
$validation->set_rules($product->rules());
|
|
|
|
if ($validation->run()) {
|
|
$product->save();
|
|
$this->session->set_flashdata('success', 'Berhasil disimpan');
|
|
}
|
|
|
|
$data = array(
|
|
'tpl_path' => $this->_tpl_path,
|
|
'content_title' => 'Tambah Produk'
|
|
);
|
|
$this->load->view($this->_tpl_path . 'product/edit',$data);
|
|
}
|
|
|
|
public function edit($id = null)
|
|
{
|
|
if (!isset($id)) redirect('admin/product');
|
|
|
|
$product = $this->m_product;
|
|
$validation = $this->form_validation;
|
|
$validation->set_rules($product->rules());
|
|
|
|
if ($validation->run()) {
|
|
$product->update();
|
|
$this->session->set_flashdata('success', 'Berhasil disimpan');
|
|
}
|
|
|
|
$data["product"] = $product->getById($id);
|
|
if (!$data["product"]) show_404();
|
|
|
|
$this->load->view("admin/product/edit_form", $data);
|
|
}
|
|
|
|
public function delete($id=null)
|
|
{
|
|
if (!isset($id)) show_404();
|
|
|
|
if ($this->product_model->delete($id)) {
|
|
redirect(site_url('admin/product'));
|
|
}
|
|
}
|
|
}
|