Yii2 kartik SELECT2ウィジェットあまりにも問題の値を示します

EmzynのPVTは株式会社:

私は以下のような複数の車種を選択するために、A yii2 kartik SELECT2ウィジェットを作成しました

<?= Select2::widget([
        'name' => 'drp-make',
        'data' => Car::getCarMakesEnglish(),
        'value' => explode(",",$model->drp_make),
        'options' => [
          'id'=>'drp-make',
          'placeholder' => 'All Makes',
          'multiple' => true
        ]
      ]); ?>

そして、機能は同様SELECT2のためのデータを取得します

 public static function getCarMakesEnglish(){
            $out=array();
        $makes=CarMakes::find()->select(['id','make_eng'])->all();
        foreach ($makes as $make) {
            array_push($out,array($make['id'] => $make['make_eng']));
        }
        return $out;
    }

問題perfect.Butその作業はthere.pleaseが絵の下に見ています

ここでは、画像の説明を入力します。

その示す値があまりにだけnames.Iはそれをするだけのメイクnames.Howを表示したくありません

ムハンマドオマールアスラム:

あなたは、すべてのインデックスに配列を推進しているので $out

array_push($out,array($make['id'] => $make['make_eng']))

あなたが使用する必要がありますyii\helpers\ArrayHelper::map()あなたのためにこれを行う代わり。あなたの関数を変更してgetCarMakesEnglish()、次へ

public static function getCarMakesEnglish()
{
    $makes = CarMakes::find()->select(['id', 'make_eng'])->all();
    return \yii\helpers\ArrayHelper::map($makes,'id','make_eng');
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=13625&siteId=1