简体   繁体   English

yii中的自动完成小部件

[英]Autocomplete widget in yii

I am trying to use the yii autocomplete build in widget. 我试图在小部件中使用yii自动完成构建。 I have manage to show results from my users table intro the input filed with the following blocks of code: 我已设法显示来自我的用户表的结果,使用以下代码块来输入输入:

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 ) {
                //
            }'
),
));

As soon as a user is selected i want to redirect to that user page. 一旦选择了用户,我想重定向到该用户页面。 I need to catch the user name in the select event. 我需要在select事件中捕获用户名。 Or an alternative way is to catch both the user name and the user id to be able to easily redirect on that id. 或者另一种方法是捕获用户名和用户ID,以便能够轻松地重定向该ID。

I hope this is a solution 我希望这是一个解决方案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM