title: Zend Jquery Autocomplete populate from Database
body: <p>Hi I am trying to implement a autocomplete field using Zend Jquery.  I followed a tutorial to grab the data from an array and I have extended the code to access the data from my mysql table.</p>
  
  <p>IndexController.php </p>
  
  <pre><code>$this-&gt;view-&gt;autocompleteElement = new ZendX_JQuery_Form_Element_AutoComplete('ac');
      $this-&gt;view-&gt;autocompleteElement-&gt;setLabel('Autocomplete');
      $this-&gt;view-&gt;autocompleteElement-&gt;setJQueryParam('source', '/index/city');
  </code></pre>
  
  <p>This calls the cityAction()</p>
  
  <pre><code>public function cityAction()
  {
      $results = Application_Model_City::search($this-&gt;_getParam('term'));
      $this-&gt;_helper-&gt;json(array_values($results));        
  }
  </code></pre>
  
  <p>I then call the Model City</p>
  
  <pre><code>public static function search($term)
  {
     $region = new Application_Model_DbTable_Regions();
  
     $results = $region-&gt;getRegion($term);
  
     return $results;
  
  }
  </code></pre>
  
  <p>And finally the Regions db model</p>
  
  <pre><code>public function getRegion($term)
  {
  
      $select = $this-&gt;select()-&gt;from($this,'City')
                                   -&gt;where('City LIKE ? ',$term.'%');
  
  
      return $this-&gt;fetchAll($select)-&gt;toArray();
  
  }
  </code></pre>
  
  <p>Now when I go the autocomplete field it shows the results but as UNDEFINED , I think its something to do the way I am send the data back to the json helper.</p>
  
  <p>I used firebug and I can see the data is been pulled in the following format.</p>
  
  <p>[{"City":"London"},{"City":"Londonderry"},{"City":"Longfield"},{"City":"Longhope"},{"City":"Longniddry"}]</p>
  
  <p>I think this format is incorrect, please any body dealt with this before?</p>
  
  <p>Cheers</p>
  
  <p>J</p>