Guest User

Untitled

a guest
Nov 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>jQuery UI Autocomplete - Default functionality</title>
  7. <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  8.  
  9.  
  10. <?php App::import('Controller','Products');App::import('Controller','Manufacturers');
  11.  
  12. <link rel="stylesheet" href="/resources/demos/style.css">
  13. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  14. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  15. <script>
  16. $( function() {
  17. var availableTags = [
  18. "ActionScript",
  19. "AppleScript",
  20. "Asp",
  21. "BASIC",
  22. "C",
  23. "C++",
  24. "Clojure",
  25. "COBOL",
  26. "ColdFusion",
  27. "Erlang",
  28. "Fortran",
  29. "Groovy",
  30. "Haskell",
  31. "Java",
  32. "JavaScript",
  33. "Lisp",
  34. "Perl",
  35. "PHP",
  36. "Python",
  37. "Ruby",
  38. "Scala",
  39. "Scheme"
  40. ];
  41. $( "#tags" ).autocomplete({
  42. source: availableTags
  43. });
  44. } );
  45. </script>
  46. </head>
  47. <body>
  48.  
  49. <div class="ui-widget">
  50. <label for="tags">Tags: </label>
  51. <input id="tags">
  52. </div>
  53.  
  54. $query = $this->params['url']['term'];
  55.  
  56. $return_arr = array();
  57. $products = $this->Product->find('all', array('fields' => array('DISTINCT (Product.product_name) AS product_name'),'conditions' => array('Product.product_name LIKE' => $query.'%')));
  58.  
  59. foreach($products as $product) {
  60. $return_arr[] = $product['Product']['product_name'];
  61. }
  62.  
  63.  
  64. echo json_encode($return_arr);
  65.  
  66. }?>
  67.  
  68. public function suggestion() {
  69. $this->autoRender = false;
  70.  
  71. $query = $this->params['url']['term'];
  72.  
  73. $return_arr = array();
  74. $manufacturers = $this->Manufacturer->find('all', array('fields' => array('Manufacturer.manufacturer'),'conditions' => array('Manufacturer.manufacturer LIKE' => $query.'%')));
  75.  
  76. foreach($manufacturers as $manufacturer) {
  77. $return_arr[] = $manufacturer['Manufacturer']['manufacturer'];
  78. }
  79.  
  80.  
  81. echo json_encode($return_arr);
  82.  
  83. }?>
Add Comment
Please, Sign In to add comment