Problem with AutoComplete (data from database)

In my views/site/index page i have used the autocomplete wideget

<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(

	'name'=>'autocompleteexample',   //every sintax is from




And in the controllers/Sitecontroller i have used

public function ActionAutocompleteTest() {

	$res =array();

	if (isset($_GET['term'])) {

		$qtxt ="SELECT name FROM {{movie}} WHERE name LIKE :name";  // movie is the table name, name is a collum

		$command =Yii::app()->db->createCommand($qtxt);

		$command->bindValue(":name", '%'.$_GET['term'].'%', PDO::PARAM_STR);

		$res =$command->queryColumn();


	echo CJSON::encode($res);



But i am not getting the expected value as a suggestion.

No suggestion is displayed.

How can i solve this problem?

And if i want to add the Search functionality to another table from getting this value what should be the good approach?

Please help me.

maybe because you write ActionAutocompleteTest()

instead of actionAutocompleteTest()

If you want only the names from movie table then u can use as array.

Like this.

$res=Yii::app()->db->createCommand('select name from movie')->queryAll();

foreach ($res as $val){



<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(





Ps. This is only the example try to make it perfect.

Why do you encode the array?

You need to return that array as you’re working with PHP, not with JS.

You can even do something like this:

'source' => CHtml::listdata(Movie::model()->findAll(


                    'condition'=>'name LIKE :name', 





            ), 'id', 'name')

The code is not tested, but it should work.

[size="5"]PHP notice[/size]

Undefined index: term

That’s probably because $_GET['term] is not set. It’s on you how to manage to make that work. I think it would work if you pass that param to the URL (?param=whatever).