1

How do I create a from dropdown holding values from enum in the specific column of the database ?

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.