Advertisement
freddy0512

controller

Nov 4th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Autocomplete extends CI_Controller {
  4.  
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->model("Mautocomplete");
  10. $this->load->library('form_validation');
  11. }
  12. public function index()
  13. {
  14.  
  15. $data['listKategori'] = $this->kategori_model->getAllKategori();
  16. $header = array(
  17. 'title' =>'Welcome to my Website'
  18. );
  19. $content = array(
  20. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  21. );
  22. $data['data_to_load'] = array($header,$content);
  23.  
  24. $data['tmp_file']='pembelian/input';
  25. $this->load->view('index',$data);
  26. }
  27.  
  28. function lookup(){
  29. // process posted form data (the requested items like province)
  30. $keyword = $this->input->post('term');
  31. $data['response'] = 'false'; //Set default response
  32. $query = $this->MAutocomplete->lookup($keyword); //Search DB
  33. if( ! empty($query) )
  34. {
  35. $data['response'] = 'true'; //Set response
  36. $data['message'] = array(); //Create array
  37. foreach( $query as $row )
  38. {
  39. $data['message'][] = array(
  40. 'id_suplier'=>$row->id_suplier,
  41. 'value' => $row->nama,
  42. ''
  43. ); //Add a row to array
  44. }
  45. }
  46. if('IS_AJAX')
  47. {
  48. echo json_encode($data); //echo json string if ajax request
  49.  
  50. }
  51. else
  52. {
  53. $header = array(
  54. 'title' =>'Welcome to my Website'
  55. );
  56. $content = array(
  57. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  58. );
  59. $data['data_to_load'] = array($header,$content);
  60.  
  61. $data['tmp_file']='pembelian/input';
  62. $this->load->view('index',$data);
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement