How to make field enum migration yii2

后端 未结 2 1161
忘掉有多难
忘掉有多难 2021-02-12 18:01

I make field ENUM and the result is error when I use yii migrate/up on CMD windows.

public function up()
{
    $tableOptions = null;
    if ($this-&         


        
2条回答
  •  抹茶落季
    2021-02-12 18:37

    Actually the best way of working this and keeping your migrations clean would be by using some tool/helper like the one provided by the yii2mod team https://github.com/yii2mod/yii2-enum

    this way you can build the enum functionality on code, works like a charm.

    i.e. an enum for genderType

     'Male',
            self::FEMALE_TYPE => 'Female',
        ];
    }
    

    Use the following methods to access your Enum:

    • createByName() - Creates a new type instance using the name of a value.
    • getValueByName() - Returns the constant key by value(label)
    • createByValue() - Creates a new type instance using the value.
    • listData() - Returns the associative array with constants values and labels
    • getLabel()- Returns the constant label by key
    • getConstantsByName() - Returns the list of constants (by name) for this type.
    • getConstantsByValue() - Returns the list of constants (by value) for this type.
    • isValidName() - Checks if a name is valid for this type. isValidValue() - Checks if a value is valid for this type.

提交回复
热议问题