Advertisement
timonte

item

Apr 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Item extends CI_Controller {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->library(array('template', 'form_validation'));
  10. $this->load->model('app_admin');
  11. }
  12.  
  13. public function index()
  14. {
  15. $data['data'] = $this->app_admin->get_all('t_items');
  16. $this->template->admin('admin/manage_item', $data);
  17. }
  18. public function add_item()
  19. {
  20. if($this->input->post('submit', TRUE) == 'Submit'){
  21.  
  22. $this->form_validation->set_rules('nama', 'Nama Item', 'required|min_length[4]');
  23. $this->form_validation->set_rules('harga', 'Harga Item', 'required|numeric');
  24. $this->form_validation->set_rules('berat', 'Berat Item', 'required|numeric');
  25. $this->form_validation->set_rules('status', 'status Item', 'required|numeric');
  26. $this->form_validation->set_rules('desk', 'Deskripsi Item', 'required|min_length[4]');
  27.  
  28. if($this->form_validation->run()== TRUE)
  29. {
  30.  
  31. $config['upload_path'] = '.asset/upload/';
  32. $config['allowed_types'] = 'gif|jpg|png';
  33. $config['max_size'] = '2048'; //KB
  34. $config['file_name'] = 'gambar' .time();
  35. $config['max_width'] = '2000'; //pixels
  36. $config['max_height'] = '2000'; //pixels
  37.  
  38. $this->load->library('upload', $config);
  39. if ( ! $this->upload->do_upload('foto'))
  40. {
  41. $gbr =$this->upload->data();
  42. $items = array(
  43. 'nama_item'=> $this->input->post('nama', TRUE),
  44. 'harga'=> $this->input->post('harga', TRUE),
  45. 'berat'=> $this->input->post('berat', TRUE),
  46. 'status'=> $this->input->post('status', TRUE),
  47. 'gambar' => $gbr['file_name'],
  48. 'deskripsi'=> $this->input->post('desk', TRUE),
  49.  
  50. );
  51. $this->app_admin->insert('t_items', $items);
  52. } else {
  53.  
  54. $this->session->set_flashdata('alert', 'anda belum mengupload foto');
  55.  
  56. }
  57. }
  58. }
  59. $data['nama'] = $this->input->post('nama', TRUE);
  60. $data['berat'] = $this->input->post('berat', TRUE);
  61. $data['harga'] = $this->input->post('harga', TRUE);
  62. $data['status'] = $this->input->post('status', TRUE);
  63. $data['desk'] = $this->input->post('desk', TRUE);
  64. $data['header'] = "Tambah Produk";
  65.  
  66. $this->template->admin('admin/item_form' , $data);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement