Advertisement
freddy0512

controler

Nov 4th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Promosi extends CI_Controller {
  4.  
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->model("promosi_model"); //constructor yang dipanggil ketika memanggil products.php untuk melakukan pemanggilan pada model : products_model.php yang ada di folder models
  10. $this->load->library('upload'); //load library upload bisa dilakukan disni atau disimpan di autoload
  11.  
  12. }
  13. public function index()
  14. {
  15.  
  16. $data['listPromosi'] = $this->promosi_model->getAllPromo();
  17. // $header berisi array data yang akan dilemparkan ke view header.php
  18. $header = array(
  19. 'title' =>'Welcome to my Website'
  20. );
  21. // $content berisi array data yang akan dilemparkan ke view content.php
  22. $content = array(
  23. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  24. );
  25. $data['data_to_load'] = array($header,$content);
  26.  
  27. $data['tmp_file']='promo/front';
  28. // load view index.php dengan beban data $data
  29. $this->load->view('index',$data);
  30. }
  31.  
  32. public function deleteProductDb($id_promo)
  33. {
  34. $this->promosi_model->deleteProduct($id_promo);
  35. redirect('promosi');
  36. }
  37.  
  38. public function updateProduct($id_pelanggan)
  39. {
  40. $data['pelanggan'] = $this->pelanggan_model->getAllPelanggan($id_pelanggan);
  41.  
  42. $data['ListPelanggan'] = $this->pelanggan_model->getAllPelanggan();
  43. // $header berisi array data yang akan dilemparkan ke view header.php
  44. $header = array(
  45. 'title' =>'Welcome to my Website'
  46. );
  47. // $content berisi array data yang akan dilemparkan ke view content.php
  48. $content = array(
  49. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  50. );
  51. $data['data_to_load'] = array($header,$content);
  52. $data['tmp_file']='promo/update_product';
  53. $this->load->view('index',$data);
  54. }
  55.  
  56. public function updateProductDb()
  57. {
  58. $data=array(
  59. 'no_ktp'=>$this->input->post('no_ktp'),
  60. 'nama_pelanggan'=>$this->input->post('nama'),
  61. 'alamat'=>$this->input->post('alamat'),
  62. 'jk'=>$this->input->post('jk'),
  63. 'nohp'=>$this->input->post('nohp'),
  64. 'email'=>$this->input->post('email'),
  65. );
  66.  
  67. $condition['id_pelanggan'] = $this->input->post('id_pelanggan');
  68. $this->pelanggan_model->updateProduct($data, $condition);
  69. redirect('pelanggan');
  70. }
  71.  
  72. public function input()
  73. {
  74. //Function yang dipanggil ketika ingin melakukan add produk kemudian menampilkan add_product_view
  75. $header = array(
  76. 'title' =>'Welcome to my Website'
  77. );
  78. // $content berisi array data yang akan dilemparkan ke view content.php
  79. $content = array(
  80. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  81. );
  82. $data['data_to_load'] = array($header,$content);
  83. $data['tmp_file']='promo/input';
  84. $this->load->view('index',$data);
  85. }
  86.  
  87. public function do_upload()
  88. {
  89. $config['upload_path'] = "./gambar/"; //lokasi folder yang akan digunakan untuk menyimpan file
  90. $config['allowed_types'] = 'gif|jpg|png|JPEG'; //extension yang diperbolehkan untuk diupload
  91. $config['file_name'] = url_title($this->input->post('file_upload'));
  92. $this->upload->initialize($config); //meng set config yang sudah di atur
  93. if( !$this->upload->do_upload('file_upload'))
  94. {
  95. echo $this->upload->display_errors();
  96. }
  97. else{
  98. $data = array(
  99. 'gambar'=>$this->upload->file_name,
  100. 'judul' => $this->input->post('judul'),
  101. 'ket' => $this->input->post('ket'),
  102. 'tgl' => $this->input->post('tgl'),
  103. 'masa_berlaku' => $this->input->post('berlaku'),
  104. );
  105.  
  106. //$this->crud->insert($data,'images');
  107.  
  108. $this->promosi_model->addProduct($data);
  109. redirect('promosi');
  110. }
  111. }
  112. }
  113.  
  114. class Remove_Img extends CI_Controller {
  115.  
  116.  
  117. public function index()
  118. {
  119. $data['listPromosi'] = $this->promosi_model->getAllPromo();
  120. // $header berisi array data yang akan dilemparkan ke view header.php
  121. $header = array(
  122. 'title' =>'Welcome to my Website'
  123. );
  124. // $content berisi array data yang akan dilemparkan ke view content.php
  125. $content = array(
  126. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  127. );
  128. $data['data_to_load'] = array($header,$content);
  129.  
  130. $data['tmp_file']='promo/front';
  131. // load view index.php dengan beban data $data
  132. $this->load->view('index',$data);
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. public function hapus($param = ""){
  140. if($param != ""){
  141. //cek nama image dari database
  142. $this->db->select('*');
  143. $this->db->where(array('id_promo'=>$param));
  144. $data = $this->db->get('tabel_promo');
  145. $result = $data->first_row('array');
  146. $nama = $result['gambar'];
  147.  
  148. //hapus image dari server
  149.  
  150. // lokasi folder image
  151. $map = $_SERVER['DOCUMENT_ROOT'];
  152. $path = $map . '/project/gambar/';
  153.  
  154. //lokasi gambar secara spesifik
  155. $image = $path.$nama;
  156. //hapus image
  157. unlink($image);
  158.  
  159. //script untuk delete data di database
  160. $this->db->delete('tabel_promo', array('id_promo'=>$param));
  161. redirect(promosi);
  162. }else{
  163. redirect('/');
  164. }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement