Revision #4 was created by jonah on Mar 25, 2009, 11:55:20 PM.
improved code formatting
Content
[...]
In your controller, create a new action to handle autocomplete lookup queries, like so:
```php
<?php
//...Action
public function actionAutoCompleteLookup()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
{
//* q is the default varGET variable name that is used by // the autocomplete widget to pass in user input
*/
$name = $_GET['q'];
// this was set with the "max" attribute of the CAutoComplete widget
$limit = $_GET['limit'];
$criteria = new CDbCriteria;
$criteria->condition = "name LIKE :sterm";
$criteria->params = array(":sterm"=>"%$name%");
$criteria->limit = $limit;
$userArray = User::model()->findAll($criteria);
$returnVal = '';
foreach($userArray as $userAccount)
{
[...]
die();
} //...
?>
```
There are a few things to notice here:
<ol>
<li>A pipe "|" delimiter is used and natively recognized by jQuery to split a returned item into parts</li>
<li>Each autocomplete item is terminated by a newline character, or "\n"; note that the newline char must be enclosed in double quotes (") not single quotes(')</li>