CAutoComplete example?

Another requirement for my forum app is to use auto completion in search. I'm writing a simple JSON action to take the query string from the text field, how do I query my action? and how do I bind this result with the CAutoComplete-widget?

If I correctly understand the CAutoComplete-class, you simply have to create a Widget and set the url-property (  to your JSON-Action.

But I can't test it now.

Below is how we use CAutoComplete in


<?php $this->widget('CAutoComplete', array(






	'htmlOptions'=>array('size'=>'50'))); ?>



public function actionSuggestApi()


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



		echo implode("n",$results);



protected function getApiSuggestions($search)




	foreach($this->getApiKeywords() as $keyword)





	return $results;



Sweeeeeet! :) Just had to create my own SearchForm (CFormModel) and point the ‘url’-property to the right action with CHtml::normalizeUrl();

When I have a look at the generated source I see there's quite a lot of JS and CSS files loaded when dealing with such an AJAX widgets (like the CAutoComplete and others), I see there is some discussion on this in another thread and an issue for it so I guess it will be some options to stuff these files together in a controlled way when you want to optimize the application for production use.