A
A
akula222016-09-15 19:37:16
Yii
akula22, 2016-09-15 19:37:16

How to insert data from the database in DepDrop-select2?

Tell me how to insert data from the database into the second select, value for some reason does not work!

<?= $form->field($model, 'id')->label('')->dropDownList(ArrayHelper::map(Platforms::find()->all(), 'id', 'name'), ['id'=>'platform_id', 'prompt' => '- ' . Yii::t('main', 'Select platform') . ' -']) ?>

  <?= $form->field($model, 'game_id')->label('')->widget(DepDrop::classname(), [
            'type' => DepDrop::TYPE_SELECT2,
            'options' => ['multiple' => true],
            'disabled' =>false,
            'pluginOptions'=>[
                'depends'=>['platform_id'],
                'placeholder'=>'- ' . Yii::t('main', 'Select games') . ' -',
                'url'=>Url::to(['/user/default/getgame'])
            ]
        ]) 
    ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
beta-it, 2016-11-25
@beta-it

You can for example like this:

if (isset($model->game_id) ){
    $gameValue = ArrayHelper::map(Game::find()->where(['id' => $model->game_id])->all(), 'id', 'name');
}else{
    $gameValue = []; 


 <?= $form->field($model, 'game_id')->label('')->widget(DepDrop::classname(), [
'data' =>$ gameValue,
            'type' => DepDrop::TYPE_SELECT2,
            'options' => ['multiple' => true],
            'disabled' =>false,
            'pluginOptions'=>[
                'depends'=>['platform_id'],
                'placeholder'=>'- ' . Yii::t('main', 'Select games') . ' -',
                'url'=>Url::to(['/user/default/getgame'])
            ]
        ]) 
    ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question