Download presentation
Presentation is loading. Please wait.
1
Pertemuan 3 Edit, Delete,Simpan
2
Membuat menu edit,delete,hapus,simpan
Tambahkan kode berikut pada file news.php setelah <td> <?php echo $row->news_data; ?> </td> : <td> <?php echo anchor('coba/edit/'.$row>id_news,'Edit'); ?> |<?php echo anchor('coba/delete/'.$row>id_news,'Delete'); ?> </td>
3
Tambahkan file baru di view dengan nama ubah.php
<html> <head> <title> </title> </head> <?php echo form_open('coba/ubah/'.$news_id->id_news); ?> <table width=500> <tr> <td> Title</td> <td> :</td> <td> <?php echo form_input('title',$news_id->news_title); ?> </td> </tr>
4
LANJUTAN DARI UBAH.PHP <tr> <td>content </td>
<td> : </td> <td> <?php echo form_textarea('content',$news_id->news_content); ?> </td> </tr> <td colspan="3"> <td><?php echo form_submit('update', 'update data'); ?> </td> <td><?php echo form_reset('reset', ' reset data'); ?> </td> </td> </table> <?php echo form_close(); ?> </body></html>
5
Tambahkan kode pada file controller yang bernama coba.php
public function ubah() { $this->load->helper('form'); if(!empty($_POST['update'])) $this->m->update_data($_POST,$id); redirect('coba/index'); } else $data['news_id'] = $this->m->get_news_id($id); $this->load->view('ubah',$data);
6
function get_news_id($id) { $this ->db->from('news')
Tambahkan kode pada file mdl_coba.php function get_news_id($id) { $this ->db->from('news') ->where('id_news',$id) ->limit(1); $q=$this->db->get(); return $q->row(); }
7
lanjutan function update_data($p,$id) { $data=array(
'news_title'=>$p['title'], 'news_content'=>$p['content'], ); $this->db->where('id_news',$id); $this->db->update('news',$data); }
8
Fungsi untuk delete public function delete($id) {
Tambahkan kode pada file coba.php di controller public function delete($id) { $this->m->delete_data($id); redirect('coba/index'); }
9
function delete_data($id) { $this->db->where('id_news',$id);
Tambahkan file pada model dengan file mdl_coba.php function delete_data($id) { $this->db->where('id_news',$id); $this->db->delete('news'); $this>db>last_query(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.