Yii Autocomplete Widget From Database

I have been trying to determine the cause of this issue for 2 days now, but to no avail. Basically I need to obtain a the values for my AutoComplete widget from the database, but it doesn’t display any record at all. However if you pass an array for the source-> array() area, then it displays the autocomplete menus.

$this->widget(‘zii.widgets.jui.CJuiAutoComplete’, array(




'source'=> $this->createUrl('hospital/autocompleteTest'),


$res =array();

if (isset($_GET[‘term’])) {

$sql ="SELECT locationName FROM locationTypes WHERE locationName LIKE :lName";

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

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

$res =$command->queryColumn();

echo CJSON::encode($res);



The problem is that when I type something into the autocomplete field the browser console displays 403 Forbidden error message. Therefore how should I modify the createUrl method in order to place the actionAutoCompleteTest out of the protected folder?

My question is how do I reference the JQuery.js file from inside the protected folder and not from the assets folder

Dear Yoosuf

Did you put the action autocompleteTest in access rules in controller.

public function accessRules()


		return array(


				'actions'=>array('index','view','autocompleteTest'),//adding the autocompleteTest



			array('allow', // allow authenticated user to perform 'create' and 'update' actions




			array('allow', // allow admin user to perform 'admin' and 'delete' actions




			array('deny',  // deny all users





Kindly check that.


Yes I did include it there, but I have used the full name actionAutoCompleteTest rather than the name autoCompleteText

Thanks a lot

I fixed my problem, thanks guys :)