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


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


    			$data = Members::find()

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




    	    	echo 'Name' .'<br>';

    			echo AutoComplete::widget([

    		         'name' => 'member_name',    

    		         'clientOptions' => [

    		        	'source' => $data,



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

    		        	$('#receipt-member_id').val(;//#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


        $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(




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'])