I am trying to use yii autocomplete assembly in widgets. I managed to show the results from the table of my users by entering the input 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'),
'options'=>array(
'showAnim'=>'fold',
'select'=>'js:function( event, ui ) {
//
}'
),
));
Once the user is selected, I want to redirect the user to this page. I need to catch the username in the select event. Or an alternative way is to catch the username and user ID in order to be able to easily redirect this identifier.
source
share