Вопрос по CAutoComplete

В одном проекте прямо на главной потребовалось сделать поисковую форму, и вот одно из полей - автокомплит. Поиск идет по базе товаров, а автокомплит - одно из полей таблицы товаров. Я наполнил таблицу парой значений и стал вводить их в форму, но увы - что-то не так. Вот код автокомплита:


<?

						$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();

    }

Подскажите, что я делаю не так. Вообщем-то код взят в одном из уроков на сайте. Но, увы, не работает почему-то.

Никто не сталкивался?

А что значит "не работает"?

яваскриптовые ошибки? или что?

Возвращает ли серверный метод результат?

У меня сделано так.

Вид:


<?php

			$this->widget('CAutoComplete',

			  array(

				 'name'=>'to', //name of the html field that will be generated

				 'url'=>array('message/recipients'), //replace controller/action with real ids

				 'max'=>15, //specifies the max number of items to display

				 'minChars'=>1, //specifies the number of chars that must be entered before autocomplete initiates a lookup

				 'delay'=>500, //number of milliseconds before lookup occurs

				 'matchCase'=>false, //match case when performing a lookup?

				 'value' => !empty($to) ? $to->username : '',

				 'htmlOptions'=>array('class' => 'text'), //any additional html attributes that go inside of the input field can be defined here

				 'methodChain'=>".result(function(event,item){\$(\"#userID\").val(item[1]);})",

				 ));

			?>

Контроллер:


public function actionRecipients()

	{

		if (!Yii::app()->request->isAjaxRequest || !isset($_GET['q']))

			return;

		$name = $_GET['q']; //q is the default var name that is used by the autocomplete widget to pass in user input

		$limit = $_GET['limit']; //this was set with the "max" attribute of the CAutoComplete widget

		$criteria = new CDbCriteria;

		$criteria->condition = "`username` LIKE :sterm AND (userID IN (SELECT userID FROM Follow WHERE followingUserID=:uID) OR userID IN (SELECT followingUserID FROM Follow WHERE userID=:uID) )";

		$criteria->params = array(":sterm"=>"%$name%", ":uID" => Yii::app()->user->id);

		$criteria->limit = $limit;

		$userArray = User::model()->findAll($criteria);

		$returnVal = '';

		foreach($userArray as $user)

		{

			$returnVal .= $user->username.'|'.$user->userID."\n";

		}

		echo $returnVal;

	}

В твой код не вникал. Надо более детальное описание ошибки. Используй firebug для отладки.

Твой код в принципе аналогичен.

Единственное - у меня нет вот этого: ‘value’ => !empty($to) ? $to->username : ‘’,

Это ты откуда берешь?

Не работает вот что, вводишь значение, причем совпадающее началом с тем, что имеется в БД. аяксовая фигня в углу поля ввода крутится, крутится, а ничего не происходит.

Еще вопрос: в ‘url’ надо указывать реальный метод контроллера, или то правило, которое я прописывал в конфиге? Т.е. реально у меня метод находится тут: goods/guest/method а по роутам он доступен goods/method/

кто-то может помочь примерами или советами? Очень надо, проект горит можно сказать =(