Since you are using CakePHP 1.1, I suggest you check out the part of the manual that deals with Helpers
If you go to "AJAX", you will see that you can do something like this in your controller:
function autocomplete () { $this->set('people', $this->Person->findAll("name LIKE '%{$this->data['Person']['name']}%'") ); $this->layout = "ajax"; }
And in your autocomplete.thtml you will have:
<ul> <?php foreach($people as $person): ?> <li><?php echo $person['Person']['name']; ?></li> <?php endforeach; ?> </ul>
To create an autocomplete field in another view, follow these steps:
<form action="/people/index" method="POST"> <?php echo $ajax->autoComplete('Person/name', '/people/autocomplete/')?> <?php echo $html->submit('View Person')?> </form>
To do this, you need to have "Ajax" in your helpers array and include the Prototype / script.aculo.us libraries.
Good luck.
Paolo bergantino
source share