В одном проекте прямо на главной потребовалось сделать поисковую форму, и вот одно из полей - автокомплит. Поиск идет по базе товаров, а автокомплит - одно из полей таблицы товаров. Я наполнил таблицу парой значений и стал вводить их в форму, но увы - что-то не так. Вот код автокомплита:
<?
$this->widget('CAutoComplete',
array(
//name of the html field that will be generated
'name'=>'good_place',
//replace controller/action with real ids
'url'=>array('goods/guest/AutoCompleteLookup'),
'max'=>10, //specifies the max number of items to display
//specifies the number of chars that must be entered
//before autocomplete initiates a lookup
'minChars'=>2,
'delay'=>500, //number of milliseconds before lookup occurs
'matchCase'=>false, //match case when performing a lookup?
//any additional html attributes that go inside of
//the input field can be defined here
'htmlOptions'=>array('size'=>'35'),
'methodChain'=>".result(function(event,item){\$(\"#good_id\").val(item[1]);})",
));
?>
В контроллере:
public function actionAutoCompleteLookup()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
{
$name = $_GET['q'];
// this was set with the "max" attribute of the CAutoComplete widget
$limit = min($_GET['limit'], 50);
$criteria = new CDbCriteria;
$criteria->condition = "good_place LIKE :sterm";
$criteria->params = array(":sterm"=>"%$name%");
$criteria->limit = $limit;
$marketsArray = Goods_mdl_good::model()->findAll($criteria);
$returnVal = '';
foreach($marketsArray as $markets)
{
$returnVal .= $markets->getAttribute('good_place').'|'.$markets->getAttribute('good_id')."\n";
}
echo $returnVal;
}
//die();
}
Подскажите, что я делаю не так. Вообщем-то код взят в одном из уроков на сайте. Но, увы, не работает почему-то.