Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. class Crud extends CI_Controller{
  4.  
  5. function __construct(){
  6. parent::__construct();
  7. $this->load->model('m_data');
  8. $this->load->helper('url');
  9. }
  10.  
  11. function index(){
  12. $data['user'] = $this->m_data->tampil_data()->result();
  13. $this->load->view('v_tampil',$data);
  14. }
  15.  
  16. function tambah(){
  17. $this->load->view('v_input');
  18. }
  19.  
  20. function tambah_aksi(){
  21. $nama = $this->input->post('nama');
  22. $alamat = $this->input->post('alamat');
  23. $pekerjaan = $this->input->post('pekerjaan');
  24. $email = $this->input->post('email');
  25.  
  26. $data = array(
  27. 'nama' => $nama,
  28. 'alamat' => $alamat,
  29. 'pekerjaan' => $pekerjaan,
  30. 'email' => $email
  31. );
  32.  
  33. $this->m_data->input_data($data,'user');
  34. redirect('crud/index');
  35. }
  36.  
  37. function hapus($id){
  38. $where = array('id' => $id);
  39. $this->m_data->hapus_data($where,'user');
  40. redirect('crud/index');
  41. }
  42.  
  43. function edit($id){
  44. $where = array('id' => $id);
  45. $data['user'] = $this->m_data->edit_data($where,'user')->result();
  46. $this->load->view('v_edit',$data);
  47. }
  48.  
  49. function update(){
  50. $id = $this->input->post('id');
  51. $nama = $this->input->post('nama');
  52. $alamat = $this->input->post('alamat');
  53. $pekerjaan = $this->input->post('pekerjaan');
  54. $email = $this->input->post('email');
  55.  
  56. $data = array(
  57. 'nama' => $nama,
  58. 'alamat' => $alamat,
  59. 'pekerjaan' => $pekerjaan,
  60. 'email' => $email
  61. );
  62.  
  63. $where = array(
  64. 'id' => $id
  65. );
  66.  
  67. $this->m_data->update_data($where,$data,'user');
  68. redirect('crud/index');
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement