Advertisement
Guest User

controller

a guest
Oct 23rd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Autocomplete extends CI_Controller {
  4.  
  5. function __construct() {
  6.  
  7.  
  8. parent::__construct();
  9. $this->load->model('MAutocomplete');
  10. }
  11.  
  12. function index(){
  13. $this->load->view('autocomplete/show');
  14. }
  15.  
  16. function lookup(){
  17. // process posted form data (the requested items like province)
  18. $keyword = $this->input->post('term');
  19. $data['response'] = 'false'; //Set default response
  20. $query = $this->MAutocomplete->lookup($keyword); //Search DB
  21. if( ! empty($query) )
  22. {
  23. $data['response'] = 'true'; //Set response
  24. $data['message'] = array(); //Create array
  25. foreach( $query as $row )
  26. {
  27. $data['message'][] = array(
  28. 'id'=>$row->propinsi_id,
  29. 'value' => $row->propinsi,
  30. ''
  31. ); //Add a row to array
  32. }
  33. }
  34. if('IS_AJAX')
  35. {
  36. echo json_encode($data); //echo json string if ajax request
  37.  
  38. }
  39. else
  40. {
  41. $this->load->view('autocomplete/index',$data); //Load html view of search results
  42. }
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement