Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-- sebelumnya:
- ubah field `idMstAppr` di table `mstappr` menjadi AUTO_INCREMENT
- // ini model nya
- <?php
- class M_crud extends CI_Model {
- public function __construct() {
- $this->load->database();
- }
- function get_crud_all() {
- $query=$this->db->query("select * from mstappr ");
- return $query->result();
- }
- function tambah_appr() {
- $data = array(
- 'MstAppr1' =>$this->input->post('MstAppr1'),
- 'MstAppr2' =>$this->input->post('MstAppr2'),
- 'MstAppr3' =>$this->input->post('MstAppr3'),
- 'MstAppr4' =>$this->input->post('MstAppr4'),
- );
- return $this->db->insert('mstappr', $data);
- }
- function get_crud_edit_appr($id) {
- $this->db->where('idMstAppr',$id);
- $query = $this->db->get('mstappr');
- if($query ->num_rows > 0)
- return $query;
- else
- return null;
- }
- function edit_appr() {
- $id = $this->input->post('idMstAppr');
- $data = array (
- 'idMstAppr'=>$this->input->post('idMstAppr'),
- 'MstAppr1' =>$this->input->post('MstAppr1'),
- 'MstAppr2' =>$this->input->post('MstAppr2'),
- 'MstAppr3' =>$this->input->post('MstAppr3'),
- 'MstAppr4' =>$this->input->post('MstAppr4'),
- );
- $this->db->where('idMstAppr',$id);
- $this->db->update('mstappr',$data);
- }
- function hapus_appr($id){
- $this->db->where('idMstAppr',$id);
- $this->db->delete('mstappr');
- }
- //ini kontroller nya
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Mstappr extends CI_Controller {
- public function __construct() {
- parent::__construct();
- $this->load->model('m_crud');
- }
- public function index() {
- $this->load->model('m_crud');
- $data['judul'] = 'Appropal';
- $data['daftar'] = $this->m_crud->get_crud_all();
- $this->load->view('master/mstappr_view', $data);
- }
- public function tambah() {
- $data['judul'] = 'Appropal';
- $this->load->view('master/mstappr_tambah', $data);
- }
- public function proses_tambah_appr() {
- $this->load->model('m_crud','',TRUE);
- $this->m_crud->tambah_appr();
- redirect('mstappr/index');
- }
- public function edit($id) {
- $data['judul'] = 'Appropal';
- $data['daftar'] = $this->m_crud->get_crud_edit_appr($id);
- $this->load->view('master/mstappr_edit',$data);
- }
- public function proses_edit() {
- $this->load->model('m_crud','',TRUE);
- $this->m_crud->edit_appr();
- redirect('mstappr/index');
- }
- public function hapus($id) {
- $this->load->model('m_crud','',TRUE);
- $this->m_crud->hapus_appr($id);
- redirect('mstappr/index');
- }
- }
- // INI VIEW NYA
- <body>
- <h1><?php echo $judul; ?></h1>
- <fieldset>
- <form method="POST" action="<?php echo site_url('mstappr/proses_tambah_appr'); ?>">
- <legend>
- <h3>Add New Appropval</h3>
- </legend>
- <table class="table-responsive">
- <tr>
- <td>Approval 1</td>
- <td><input type="text" name="MstAppr1" placeholder="MstAppr1"/></td>
- </tr>
- <tr>
- <td>Approval 2</td>
- <td><input type="text" name="MstAppr2" placeholder="MstAppr2"/></td>
- </tr>
- <tr>
- <td>Approval 3</td>
- <td><input type="text" name="MstAppr3" placeholder="MstAppr3"/></td>
- </tr>
- <tr>
- <td>Approval 4</td>
- <td><input type="text" name="MstAppr4" placeholder="MstAppr4"/></td>
- </tr>
- <tr>
- <td> </td>
- <td width="140">
- <input type="submit" name="simapn" value="Simpan" class="submitButton">
- </td>
- </tr>
- </table>
- </form>
- </fieldset>
- <hr>
- <table cellpadding="5" cellspacing="5" width="100%" class="table-striped table-bordered table-hover">
- <tr>
- <th id="judul">No</td>
- <th id="judul">Appropal1</td>
- <th id="judul">Appropal3</td>
- <th id="judul">Appropal3</td>
- <th id="judul">Appropal4</td>
- <th id="judul" colspan="2">Action</td>
- </tr>
- <?php foreach ($daftar as $a) {?>
- <tr id="hd" class="hd">
- <td class="hd"><?php echo $a->idMstAppr; ?></td>
- <td class="hd"><?php echo $a->MstAppr1; ?></td>
- <td class="hd"><?php echo $a->MstAppr2; ?></td>
- <td class="hd"><?php echo $a->MstAppr3; ?></td>
- <td class="hd"><?php echo $a->MstAppr4; ?></td>
- <td class="hd">
- <a href="<?php echo site_url ('mstappr/edit/'.$a->idMstAppr)?>">
- <input type="submit" value="Edit" class="submitButton">
- </a>
- </td>
- <td class="hd">
- <a href="<?php echo site_url ('mstappr/hapus/'.$a->idMstAppr)?>">
- <input type="submit" value="Delete" class="submitButton">
- </a>
- </td>
- </tr>
- <?php } ?>
- </table>
- <hr>
- <p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement