How do I create a from dropdown holding values from enum in the specific column of the database ?
1 Answer
This is how gii generator works:
$model = new MyModel; // this is your model
$tableSchema = $model->getTableSchema();
$column = $tableSchema->columns['my_column']; // the column that has enum values
if (is_array($column->enumValues) && count($column->enumValues) > 0) {
$dropDownOptions = [];
foreach ($column->enumValues as $enumValue) {
$dropDownOptions[$enumValue] = \yii\helpers\Inflector::humanize($enumValue);
}
}
this will generate you $dropDownOptions with the enum values.