2014-04-22 39 views
2

我的Widget在View.php文件Yii的CjuiAutoComplete不工作怎麼解決這個錯誤

<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文本中後段 顯示如何解決這個

+0

'源'=> '類別/ getsearchcats',替換 'sourceUrl'=>數組( '類別/ getsearchcats'), – user1852788

回答

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); 
相關問題