Page 74 - Framework Codeigniter 2
P. 74

www.koder.web.id – Kumpulan tutorial komputer

            Selain  untuk  menampilkan  data,  controller  tadi  memiliki  fungsi  ubah  dan  tambah  data  siswa.
            Kedua fungsi tersebut pada intinya sama. Perbedaannya adalah action  atau fungsi model yang
            dipanggil dan pemanggilan record yang akan di edit. Perhatikan fungsi add pada baris 82. Pada

            fungsi  add  tersebut  dilakukan  pemanggilan  terhadap  fungsi  $this->_set_rules();  fungsi
            tersebut  digunakan  untuk  mengeset  validation  rule.  Jika  inputan  yang  dimasukkan  oleh  user

            sesuai  dengan  rule  validasi  maka  akan  dipanggil  fungsi  $this->siswa_model->save  untuk
            menyimpan data tersebut. Adapun view yang digunakan adalah


            1.    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            3.    <htmlxmlns="http://www.w3.org/1999/xhtml">
            4.    <head>
            5.    <metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/>
            6.    <title>SIMPLE CRUD APPLICATION</title>
            7.    <linkhref="<?php echo base_url();?>style/style.css"
            8.    rel="stylesheet"type="text/css"/>
            9.    </head>
            10.  <body>
            11.  <divclass="content">
            12.  <h1><?php echo $title;?></h1>
            13.  <?php echo $message;?>
            14.  <?php echo validation_errors();?>
            15.  <?php echo form_open($action);?>
            16.  <divclass="data">
            17.  <table>
            18.  <tr>
            19.  <tdwidth="30%">ID</td>
            20.  <td><inputtype="text"name="id"disabled="disable"class="text"
            21.  value="<?php echo (isset($siswa['id']))?$siswa['id']:'';?>"/></td>
            22.  <inputtype="hidden"name="id"value="<?php echo
            23.  (isset($siswa['id']))?$siswa['id']:'';?>"/>
            24.  </tr>
            25.  <tr>
            26.  <tdvalign="top">nama<spanstyle="color:red;">*</span></td>
            27.  <td><inputtype="text"name="nama"class="text"value="<?php echo
            28.  (set_value('nama'))?set_value('nama'):$siswa['nama'];?>"/>
            29.  <?php echo form_error('nama');?></td>
            30.  </tr>
            31.  <tr>
            32.  <tdvalign="top">Alamat</td>
            33.  <td><inputtype="text"name="alamat"class="text"value="<?php echo
            34.  set_value('alamat')?set_value('alamat'):$siswa['alamat'];?>"/>
            35.  <?php echo form_error('alamat');?></td>
            36.  </tr>
            37.  <tr>
            38.  <tdvalign="top">jenis_kelamin<spanstyle="color:red;">*</span></td>
            39.  <td><inputtype="radio"name="jenis_kelamin"value="M"<?php echo
            40.  set_radio('jenis_kelamin','M', TRUE);?>/> Laki-Laki
            41.  <inputtype="radio"name="jenis_kelamin"value="F"<?php echo
            42.  set_radio('jenis_kelamin','F');?>/> Perempuan
            43.  <?php echo form_error('jenis_kelamin');?></td>
            44.  </tr>
            45.  <tr>
            46.  <tdvalign="top">Date of birth (dd-mm-yyyy)<span
            47.  style="color:red;">*</span></td>
            48.  <td><inputtype="text"name="tanggal_lahir"class="text"
            49.  value="<?php echo (set_value('tanggal_lahir'))?
            50.  set_value('tanggal_lahir'):$siswa['tanggal_lahir'];?>"/>
                                                                                                          69
   69   70   71   72   73   74   75   76   77   78   79