toko/application/controllers/admin/Product.php

73 lines
1.8 KiB
PHP
Raw Normal View History

2020-01-09 11:23:07 +07:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Product extends CI_Controller {
2020-01-09 17:06:18 +07:00
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');
}
2020-01-09 11:23:07 +07:00
public function index()
{
2020-01-09 17:06:18 +07:00
$product = $this->m_product;
2020-01-09 11:23:07 +07:00
$data = array(
2020-01-09 17:06:18 +07:00
'tpl_path' => $this->_tpl_path,
'products' => $product->getAll()
2020-01-09 11:23:07 +07:00
);
2020-01-09 17:06:18 +07:00
$this->load->view($this->_tpl_path . 'product/list',$data);
2020-01-09 11:23:07 +07:00
}
2020-01-09 17:06:18 +07:00
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'));
}
}
2020-01-09 11:23:07 +07:00
}