Skip to content

Instantly share code, notes, and snippets.

@taleeb35
Created September 18, 2014 00:59
Show Gist options
  • Save taleeb35/f4f8826ed02d530309c5 to your computer and use it in GitHub Desktop.
Save taleeb35/f4f8826ed02d530309c5 to your computer and use it in GitHub Desktop.
public function find() {
$this->Country->recursive = -1;
if ($this->request->is('ajax')) {
$this->autoRender = false;
$country_name = $this->request->data['Country']['name'];
$results = $this->Country->find('all', array(
'conditions' => array('Country.name LIKE ' => '%' . $country_name . '%')
));
foreach($results as $result) {
echo $result['Country']['name'] . "\n";
}
}
}
<?php
echo $this->Form->create('Country', array('action' => 'find'));
echo $this->Form->input('name',array('id' => 'Autocomplete'));
echo $this->Form->submit();
echo $this->Form->end();
?>
<script type="text/javascript">
$(document).ready(function($){
$('#Autocomplete').autocomplete({
source:'/countries/find',
minLength:2
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment