I have an issue with the CJuiAutoComplete in Yii and using it with a model. I've been able to run a query within the function and pass that back, but not with using a model. It just returns no results. Can anyone see where the issue is?
This is the code in the controller:
public function actionAutocompleteTest() {
$arr = array();
foreach($models as $m开发者_StackOverflow社区odel) {
$arr[] = array(
'label'=>$model->pID, // label for dropdown list
'value'=>$model->pID, // value for input field
'id'=>$model->pName, // return value from autocomplete
);
}
echo CJSON::encode($arr);
Yii::app()->end();
}
This is the code on the page:
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>'Players',
'attribute'=>array('pID', 'pName'),
'name'=>'test',
'source'=>$this->createUrl('jui/autocompleteTest'),
// additional javascript options for the autocomplete plugin
'options'=>array(
'showAnim'=>'fold',
'select'=>'alert("hello"); return true;'
),
));
?>
actionAutocompleteTest will get the data sent by CJuiAtoComplete via post. So, you have to use the data to filter the results from the post, run the query and return the results.
精彩评论