I am trying to display a dropdown with a category in the yii2 structure.
The tables in my database are configured using a foreign key and the Model and Crud generator are used to generate the code.
I am trying to change the code now to change the text box in the drop-down list with the values from the category table.
<?php $categoryArray = ArrayHelper::map(\app\models\Category::find()->orderBy('name')->all(), 'id', 'name') ?>
<?= $form->field($model, 'category_id')->dropDownList($categoryArray, ['prompt' => '---- Select category ----'])->label('category') ?>
This returns with the error "2.yii \ base \ ErrorHandler :: handleFatalError ()"
Most of the related messages with my problem relate to version 1 of the structure, but cannot find a good example of how to do this with version 2.
source
share