0

I need help on the select widget for kartik as used in yii2 advanced template. Data is being fetched correctly and i can print it using the print_r function.

<?php
        $facultiesData = Faculties::find()
                        ->select(['faculty_id','faculty_name'])
                        ->asArray()
                        ->all();
        $facultiesData = ArrayHelper::map( $facultiesData, 'faculty_id','faculty_name' );

        print_r($facultiesData); //print values on screen

     ?>

the problem is,this data is not being populated in the form field with kartik select widget

<?=  $form->field($model, 'faculty_id')->widget(Select2::classname(), [
        'data' => $facultiesData,
        'language' => 'en',
        'options' => ['placeholder' => 'choose property ...'],
        'pluginOptions' => [
            'allowClear' => true
        ],
     ]); 
  ?>

this is what is showing enter image description here

Thanks in advance. I will appreciate any lead or help

Shammir
  • 927
  • 4
  • 17
  • 32

1 Answers1

0

I resolved the problem. In the code

<?php
    $facultiesData = Faculties::find()
                    ->select(['faculty_id','faculty_name'])
                    ->asArray()
                    ->all();
    $facultiesData = ArrayHelper::map( $facultiesData, 'faculty_id','faculty_name' );

    print_r($facultiesData); //print values on screen

 ?>

I removed "->select()->asArray() to remain with find()->all() "

The function asArray() returns values as [34=>"any"] but the widget requires data as 34=>"any" as for my understaing.

Shammir
  • 927
  • 4
  • 17
  • 32