2016-05-25 12 views
-2

Zeigt Namen von MilliStones in activeDropDownList von Yii2, aber jetzt will ich ein anderes Feld mit ihm verketten (Like Anzahl von Millistone).Verkettung in Yii2 activeDropDownList

z. B. (Milli Stone Name - Anzahl der Steine).

<?= Html::activeDropDownList($model, 'milli_stone_id',ArrayHelper::map(MilliStones::find()->where(['cat_id' => $Rings->milli_cat])->all(), 'id', 'name'),['prompt'=>'Select Milli Stone','class'=>'form-control']) ?> 

Antwort

0
<?= Html::activeDropDownList($model, 'milli_stone_id',ArrayHelper::map(MilliStones::find()->where(['IN', 'id', $IdsArray2])->asArray()->all(), 
        'id', 
        function($model, $defaultValue) { 
         return $model['id'].'-'.$model['name']; 
        } 
       ),['prompt'=>'Select Milli Stone','class'=>'form-control']) ?> 
+0

ref: http://stackoverflow.com/questions/27768540/yii2drop-down-list-for- Multiple-Werte-Concat-in-One-Linie arbeitete wie ein Charme. –

0

Sie sollten eine select-Klausel in Fund() verwenden, auf diese Weise

<?= Html::activeDropDownList($model, 'milli_stone_id', 
     ArrayHelper::map(MilliStones::find()-> 
      select('id, concat(name, id) as name ')-> 
      where(['cat_id' => $Rings->milli_cat])->all(), 'id', 'name'), 
     ['prompt'=>'Select Milli Stone','class'=>'form-control']) ?>