2011-12-23 84 views
5

我正嘗試使用小部件中的yii自動填充構建。我必須設法展現從我的用戶表介紹了輸入與下面的代碼塊申請結果:yii中的自動填充小部件

public function actionSearch() 
{ 
    $res =array(); 
if (isset($_GET['term'])) 
    {   
     $qtxt ="SELECT user FROM tbl_user WHERE user LIKE :user"; 
     $command =Yii::app()->db->createCommand($qtxt); 
     $command->bindValue(":user", '%'.$_GET['term'].'%', PDO::PARAM_STR); 
     $res =$command->queryColumn(); 
    } 
echo CJSON::encode($res);  
    Yii::app()->end(); 
} 

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1', 
'source'=>$this->createUrl('user/search'), 
// additional javascript options for the autocomplete plugin 
'options'=>array(
      'showAnim'=>'fold', 
      'select'=>'js:function(event, ui) { 
       // 
      }' 
), 
)); 

作爲一個用戶選擇了不久,我想重定向到該用戶的頁面。我需要在select事件中捕獲用戶名。或者,另一種方法是同時捕獲用戶名和用戶ID,以便能夠輕鬆地在該ID上重定向。

回答

3

我希望這是一個解決方案

'select' => 'js:function(event, ui){ 
    // ui.item.id 
    // ui.item.name 
    top.location = "/user/view/?id=" + ui.item.id; 
}' 
相關問題