Advertisement
cdsatrian

mstappr

Oct 9th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. //-- sebelumnya:
  2.  
  3. ubah field `idMstAppr` di table `mstappr` menjadi AUTO_INCREMENT
  4.  
  5. // ini model nya
  6. <?php
  7. class M_crud extends CI_Model {
  8.   public function __construct() {
  9.    $this->load->database();
  10.   }
  11.   function get_crud_all() {
  12.     $query=$this->db->query("select * from mstappr ");
  13.     return $query->result();
  14.   }
  15.  
  16.   function tambah_appr() {
  17.    $data = array(
  18.      'MstAppr1' =>$this->input->post('MstAppr1'),
  19.      'MstAppr2' =>$this->input->post('MstAppr2'),
  20.      'MstAppr3' =>$this->input->post('MstAppr3'),
  21.      'MstAppr4' =>$this->input->post('MstAppr4'),
  22.    );
  23.    return $this->db->insert('mstappr', $data);
  24.   }
  25.   function get_crud_edit_appr($id) {
  26.    $this->db->where('idMstAppr',$id);
  27.    $query = $this->db->get('mstappr');
  28.    if($query ->num_rows > 0)
  29.    return $query;
  30.    else
  31.    return null;
  32.   }
  33.   function edit_appr() {
  34.     $id = $this->input->post('idMstAppr');
  35.     $data = array (
  36.     'idMstAppr'=>$this->input->post('idMstAppr'),
  37.     'MstAppr1' =>$this->input->post('MstAppr1'),
  38.     'MstAppr2' =>$this->input->post('MstAppr2'),
  39.     'MstAppr3' =>$this->input->post('MstAppr3'),
  40.     'MstAppr4' =>$this->input->post('MstAppr4'),
  41.     );
  42.     $this->db->where('idMstAppr',$id);
  43.     $this->db->update('mstappr',$data);
  44.   }
  45.   function hapus_appr($id){
  46.     $this->db->where('idMstAppr',$id);
  47.     $this->db->delete('mstappr');
  48.   }
  49.  
  50.  
  51.  
  52. //ini kontroller nya
  53.  
  54. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  55.   class Mstappr extends CI_Controller {
  56.     public function __construct() {
  57.       parent::__construct();
  58.       $this->load->model('m_crud');
  59.     }
  60.  
  61.     public function index() {
  62.       $this->load->model('m_crud');
  63.       $data['judul'] = 'Appropal';
  64.       $data['daftar'] = $this->m_crud->get_crud_all();
  65.       $this->load->view('master/mstappr_view', $data);
  66.     }
  67.  
  68.     public function tambah() {
  69.       $data['judul'] = 'Appropal';
  70.       $this->load->view('master/mstappr_tambah', $data);
  71.     }
  72.  
  73.     public function proses_tambah_appr() {
  74.       $this->load->model('m_crud','',TRUE);
  75.       $this->m_crud->tambah_appr();
  76.       redirect('mstappr/index');
  77.     }
  78.  
  79.     public function edit($id) {
  80.       $data['judul'] = 'Appropal';
  81.       $data['daftar'] = $this->m_crud->get_crud_edit_appr($id);
  82.       $this->load->view('master/mstappr_edit',$data);
  83.     }
  84.  
  85.     public function proses_edit() {
  86.       $this->load->model('m_crud','',TRUE);
  87.       $this->m_crud->edit_appr();
  88.       redirect('mstappr/index');
  89.     }
  90.  
  91.     public function hapus($id) {
  92.        $this->load->model('m_crud','',TRUE);
  93.        $this->m_crud->hapus_appr($id);
  94.        redirect('mstappr/index');
  95.     }
  96.   }
  97.  
  98.  
  99.  
  100. // INI VIEW NYA
  101. <body>
  102.   <h1><?php echo $judul; ?></h1>
  103.   <fieldset>
  104.     <form method="POST" action="<?php echo site_url('mstappr/proses_tambah_appr'); ?>">
  105.       <legend>
  106.         <h3>Add New Appropval</h3>
  107.       </legend>
  108.       <table class="table-responsive">
  109.         <tr>
  110.           <td>Approval 1</td>
  111.           <td><input type="text" name="MstAppr1" placeholder="MstAppr1"/></td>
  112.         </tr>
  113.         <tr>
  114.           <td>Approval 2</td>
  115.           <td><input type="text" name="MstAppr2" placeholder="MstAppr2"/></td>
  116.         </tr>
  117.         <tr>
  118.           <td>Approval 3</td>
  119.           <td><input type="text" name="MstAppr3" placeholder="MstAppr3"/></td>
  120.         </tr>
  121.         <tr>
  122.           <td>Approval 4</td>
  123.           <td><input type="text" name="MstAppr4" placeholder="MstAppr4"/></td>
  124.         </tr>
  125.         <tr>
  126.           <td>&nbsp;</td>
  127.           <td width="140">
  128.             <input type="submit" name="simapn" value="Simpan" class="submitButton">
  129.           </td>
  130.         </tr>
  131.       </table>  
  132.     </form>
  133.   </fieldset>
  134.   <hr>
  135.   <table cellpadding="5" cellspacing="5" width="100%" class="table-striped table-bordered table-hover">
  136.     <tr>
  137.       <th id="judul">No</td>
  138.         <th id="judul">Appropal1</td>
  139.         <th id="judul">Appropal3</td>
  140.         <th id="judul">Appropal3</td>
  141.         <th id="judul">Appropal4</td>
  142.         <th id="judul" colspan="2">Action</td>
  143.       </tr>
  144.       <?php foreach ($daftar as $a)   {?>
  145.       <tr id="hd" class="hd">
  146.          <td class="hd"><?php echo $a->idMstAppr; ?></td>
  147.          <td class="hd"><?php echo $a->MstAppr1; ?></td>
  148.          <td class="hd"><?php echo $a->MstAppr2; ?></td>
  149.          <td class="hd"><?php echo $a->MstAppr3; ?></td>
  150.          <td class="hd"><?php echo $a->MstAppr4; ?></td>
  151.          <td class="hd">
  152.           <a href="<?php echo site_url ('mstappr/edit/'.$a->idMstAppr)?>">
  153.             <input type="submit" value="Edit" class="submitButton">
  154.           </a>
  155.          </td>
  156.          <td class="hd">
  157.           <a href="<?php echo site_url ('mstappr/hapus/'.$a->idMstAppr)?>">
  158.             <input type="submit" value="Delete" class="submitButton">
  159.           </a>
  160.          </td>
  161.       </tr>
  162.       <?php } ?>
  163.     </table>
  164.     <hr>
  165.     <p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement