How to read out foreign-key value in kartik-Widget?

Following code reads out value of foreign key in lookup-table correctly,but it fails in combobox using Kartik-Widget GridView/Select2. Any ideas,how to fix this problem?




.

.

.

   [

            'attribute' => 'rechtsart',

            'label' => Yii::t('app', 'Rechtsart'),

            'value' => function($model){

                if ($model->rechtsart0)

                {return $model->rechtsart0->art;}

                else

                {return NULL;}

            },

            'filterType' => GridView::FILTER_SELECT2,

            'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'rechtsart0.art'),

    'filterWidgetOptions' => [

                'pluginOptions' => ['allowClear' => true],

            ],

            'filterInputOptions' => ['placeholder' => 'Rechtsform', 'id' => 'grid-bewerbungen-search-rechtsart']

        ],...



I get no values at all in Combobox.

Following code will get naked values, but this is not very useful,isn’t it?




.

.

.

 'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'id_recht'),...



What are the columns in the Rechtsform table? Are you asking for fields that aren’t there? Another thing you could do is in the ‘Rechtsform’ model and a method.




/**

 * get list of Rechtsform for dropdown

 */

public static function getRechtsformList() {

    $droptions = Rechtsform::find()->asArray()->all();

    return ArrayHelper::map($droptions, 'id', 'value');

}



Then your ‘filter’ could be




'filter' => Rechtsform::getRechtsformList(),



Thx.Your hints helped solving my problem. Ur the Greatest!

Glad to help. If my answer didn’t actually answer your question, posting your solution could help others :D