How to concatenate two columns into an autocomplete field in yii2?

hi,

i have a auto complete field in my view whose code is as follows





<?php

    			$data = Members::find()

    	    	->select(['first_name as value', 'first_name as  label','id as id'])

    	    	->asArray()

    	    	->all();

    

    	    	echo 'Name' .'<br>';

    			echo AutoComplete::widget([

    		         'name' => 'member_name',    

    		         'clientOptions' => [

    		        	'source' => $data,

    		        	'minLength'=>'3', 

    		        	'autoFill'=>true,

    		        	'select' => new JsExpression("function( event, ui ) {

    		        	$('#receipt-member_id').val(ui.item.id);//#receipt-member_id is the id of hiddenInput.

    		         }")],

    		         ]);

    	    	?>

    

 <?= Html::activeHiddenInput($model, 'member_id')?>



auto complete works correctly, it shows the first name of all the ‘members’.

But there can be many guys with similar first name, so what i want is to concatenate first_name and last_name. In normal dropdowns it can be done as follows





 <?php

        $models1 = Members::find()->all();

    	$data = array();

    	foreach ($models1 as $model1)

    		$data[$model1->id] = $model1->first_name . ' '. $model1->last_name;

    

    	echo $form->field($model, 'member_id')->dropDownList(

                                    $data,

                                    ['prompt'=>'Select...']);

    ?>



how can i do this with the autocomplete widget?

U can use concat in the select query…


->select(['CONCAT(first_name, " ", last_name) AS value', 'CONCAT(first_name, " ", last_name) AS label', 'id as id'])

thanks