freddy0512

controller

Oct 31st, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Kategori extends CI_Controller {
  4.  
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->model("kategori_model"); //constructor yang dipanggil ketika memanggil products.php untuk melakukan pemanggilan pada model : products_model.php yang ada di folder models
  10. }
  11.  
  12. public function index()
  13. {
  14. $data['listKategori'] = $this->kategori_model->getAllKategori();
  15. // $header berisi array data yang akan dilemparkan ke view header.php
  16. $header = array(
  17. 'title' =>'Welcome to my Website'
  18. );
  19.  
  20. // $content berisi array data yang akan dilemparkan ke view content.php
  21. $content = array(
  22. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  23. );
  24.  
  25.  
  26. // kumpulkan data yang akan dilemparkan ke view index.php
  27. $data['data_to_load'] = array($header,$content);
  28.  
  29. $data['tmp_file']='kategori/front';
  30. // load view index.php dengan beban data $data
  31. $this->load->view('index',$data);
  32. }
  33.  
  34. public function deleteProductDb($id_kategori)
  35. {
  36. $this->kategori_model->deleteProduct($id_kategori);
  37. redirect('kategori');
  38. }
  39.  
  40. public function updateProduct($id_kategori)
  41. {
  42. $data['product'] = $this->kategori_model->getProduct($id_kategori);
  43.  
  44.  
  45. $data['tmp_file']='kategori/update_product';
  46. // load view index.php dengan beban data $data
  47. $this->load->view('index',$data);
  48. }
  49.  
  50. public function updateProductDb()
  51. {
  52. $data=array(
  53. 'id_kategori'=>$this->input->post('id_kategori'),
  54. 'kategori'=>$this->input->post('kategori'));
  55. $condition['id_kategori'] = $this->input->post('id_kategori');
  56. $this->kategori_model->updateProduct($data, $condition);
  57. redirect('kategori');
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment