In Yii2, I want one of the input fields to be autocompleted when the user starts typing. Below my code uses Jui Autocomplete .
<?php $items= ArrayHelper::map(Company::find()->all(), 'c_id', 'name'); echo AutoComplete::widget([ 'model' => $model, 'attribute' => 'company', 'clientOptions' => [ 'source' => $items, ], ]);?>
This does not work. When I printed my array, I got how
Array ( [1] => abc [2] => xyz [4] => pqr )
I worked when I manually set how
$items=['abc','xyz','pqr'];
Perhaps the reason is that my c_id's not ordered, but I want to get the c_id value. Any idea how to fix this?
php autocomplete yii2
Dency GB
source share