I'm setting up jQuery UI autocomplete on a CakePHP site, and feel like I'm missing something really obvious, but it's almost working...
So the simple jQuery code is:
$(function() {
$("#SearchQuery").autocomplete({
source: "<?= $session->base ?>/search/complete",
minLength: 2
});
});
This connects to my search controller, and the search controller returns items from the database. I can get the results back if I don't try to actually look at the "term" (what has been typed. So, in my controller this works:
function complete(){
$entries = $this->Entry->find('list');
$this->set('entries', $entries);
}
It is returned as JSON, and drops down from the input like it should. But it never narrows the results based on what has been typed. I would think that this should narrow the results:
function complete($query = null){
$entries = $this->Entry->find('list',
array('conditions' => array('title LIKE' => '%'.$query.'%')));
$this->set('entries', $entries);
}
But with this code nothing is ever returned. What am I doing wrong?
P.S. People who find this question and are having trouble getting the results back to the autocomplete function, be sure you're returning properly formatted JSON results: http://www.pagebakers.nl/2007/06/05/using-json-in-cakephp-12/