Yii CjuiAutoComplete不工作如何解决此错误

时间:2014-04-22 11:02:15

标签: php yii

View.php文件中的我的窗口小部件是

<div class="modal-body" id="test_modal" style="display: none;">

<?php
$recipeModel = new Recipe();
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'user-form',
    'enableAjaxValidation' => true,
        //'focus'=>array($model,'firstName'),
));

$modelCat = new Category;
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'model' => $modelCat,
    'name' => 'cat_name',
    'source' => 'Category/getsearchcats',
    'options' => array(
        'minLength' => '1',
    ),
    'htmlOptions' => array(
        'style' => 'height:20px;',
    ),
));

//

echo '<p id="getdatevalue">One fine body...</p>';
$this->endWidget();
?>

和我在控制器中的getsearchcats函数是

 public function actiongetsearchcats() {
    $request = trim($_GET['term']);
    if ($request != '') {
        $model = Category::model()->findAll(array("condition" => "cat_name like '$request%'"));
        $data = array();
        foreach ($model as $get) {
            $data[] = $get->cat_name;
        }
       // $this->layout = 'empty';
        echo json_encode($data);
    }
}

但没有生成下拉列表并且没有触发任何内容,控制台只显示params中的文本,整个页面html显示在post部分中 如何解决这个问题

1 个答案:

答案 0 :(得分:0)

以下是我为搜索页面创建的示例

echo CHtml::hiddenField('url','');

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
   'name'=>'searchbox',
   'value'=>'',
   'source'=>CController::createUrl('/site/autoComplete'),
   'options'=>array(
   'showAnim'=>'fold',             
   'minLength'=>'2',
   'select'=>'js:function( event, ui ) {
       $("#searchbox").val( ui.item.label );
       $("#url").val( ui.item.url );
       this.form.submit();
       return false;
    }',
    ),
    'htmlOptions'=>array(
        $("#selected_id").val(null); $("#selected_type").val(null);',
        'class' => 'input-xxlarge',
        'id' => 'appendedInputButtons',
        'placeholder' => "Start Search",
    ),
    ));

控制器

foreach($model as $pub){
   $data['value'] = $pub['label'];
   $data['label'] = $pub['label'];
   $list[] = $data;
}

echo json_encode($list);