admin crud produk
This commit is contained in:
@ -2,14 +2,71 @@
|
||||
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()
|
||||
{
|
||||
$tpl = config_item('admin_template');
|
||||
$tpl_path = 'admin/' . $tpl . '/';
|
||||
|
||||
$product = $this->m_product;
|
||||
|
||||
$data = array(
|
||||
'tpl_path' => $tpl_path
|
||||
'tpl_path' => $this->_tpl_path,
|
||||
'products' => $product->getAll()
|
||||
);
|
||||
$this->load->view($tpl_path . 'product',$data);
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user