More information about this topic
Reset database
 | 
Autocomplete with Ajax datasource

protected/modules/UiModule/views/jui/zii_autocomplete.php


$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
	'name'=>'test1',
	'value'=>'test21',
	'source'=>$this->createUrl('jui/autocompleteTest'),
	// additional javascript options for the autocomplete plugin
	'options'=>array(
			'showAnim'=>'fold',
	),
));

protected/modules/UiModule/controllers/JuiController.php

	public function actionAutocompleteTest() {
		$res =array();

		if (isset($_GET['term'])) {
			// http://www.yiiframework.com/doc/guide/database.dao
			$qtxt ="SELECT username FROM {{user}} WHERE username LIKE :username";
			$command =Yii::app()->db->createCommand($qtxt);
			$command->bindValue(":username", '%'.$_GET['term'].'%', PDO::PARAM_STR);
			$res =$command->queryColumn();
		}

		echo CJSON::encode($res);
		Yii::app()->end();
	}
Autocomplete with Array datasource

protected/modules/UiModule/views/jui/zii_autocomplete.php


$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
	'name'=>'test2',
	'source'=>array('ac1', 'ac2', 'ac3'),
));
Fork me on GitHub