开发者

Using models with CJuiAutoComplete in Yii

开发者 https://www.devze.com 2023-03-15 01:23 出处:网络
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 result

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号