Version: current

# Class Enum

Represents an enumeration field.

  Object
  ViewableData implements IteratorAggregate
  DBField
  Enum

### Direct known subclasses

`MultiEnum`

Package: sapphire\model
Located at sapphire/core/model/fieldtypes/Enum.php

## Methods summary

`public` | # `__construct( enum: $name, `Enum::$default` $enum = NULL, mixed $default = NULL )` Create a new Enum field. You should create an enum field like this: "MyField" => "Enum('Val1, Val2, Val3', 'Val1')" or: "MyField" => "Enum(Array('Val1', 'Val2', 'Val3'), 'Val1')" but NOT: "MyField" => "Enum('Val1', 'Val2', 'Val3', 'Val1')" Create a new Enum field. You should create an enum field like this: "MyField" => "Enum('Val1, Val2, Val3', 'Val1')" or: "MyField" => "Enum(Array('Val1', 'Val2', 'Val3'), 'Val1')" but NOT: "MyField" => "Enum('Val1', 'Val2', 'Val3', 'Val1')" #### Parameters $name enum: A string containing a comma separated list of options or an array of Vals. $enum default The default option, which is either NULL or one of the items in the enumeration. $default #### Overrides `DBField::__construct`
`public` | # `requireField( )` Add the field to the underlying database. Add the field to the underlying database.
`public` | # `formField( mixed $title = null, mixed $name = null, mixed $hasEmpty = false, mixed $value = "", mixed $form = null, mixed $emptyString = null )` Return a dropdown field suitable for editing this field Return a dropdown field suitable for editing this field
`public `FormField`` | # `scaffoldFormField( string $title = null, mixed $params = null )` Returns a FormField instance used as a default for form scaffolding. Returns a FormField instance used as a default for form scaffolding. Used by `SearchContext`, `ModelAdmin`, `DataObject::scaffoldFormFields()` #### Parameters $title string $title Optional. Localized title of the generated instance $params #### Returns ``FormField`` FormField #### Overrides `DBField::scaffoldFormField`
`public `FormField`` | # `scaffoldSearchField( string $title = null )` Returns a FormField instance used as a default for searchform scaffolding. Returns a FormField instance used as a default for searchform scaffolding. Used by `SearchContext`, `ModelAdmin`, `DataObject::scaffoldFormFields()`. #### Parameters $title string $title Optional. Localized title of the generated instance #### Returns ``FormField`` FormField #### Overrides `DBField::scaffoldSearchField`
`public boolean` | # `hasValue( )` Determines if the field has a value which is not considered to be 'null' in a database context. Determines if the field has a value which is not considered to be 'null' in a database context. #### Returns `boolean` boolean #### Overrides `DBField::hasValue`
`public` | # `enumValues( mixed $hasEmpty = false )` Return the values of this enum, suitable for insertion into a dropdown field. Return the values of this enum, suitable for insertion into a dropdown field.
`public` | # `Lower( )`
`public` | # `Upper( )`

### Methods inherited from DBField

`ATT()`, `HTML()`, `HTMLATT()`, `JS()`, `LowerCase()`, `RAW()`, `RAWURLATT()`, `URLATT()`, `UpperCase()`, `XML()`, `addToQuery()`, `create()`, `debug()`, `defaultSearchFilter()`, `exists()`, `forTemplate()`, `getName()`, `getValue()`, `nullValue()`, `prepValueForDB()`, `saveInto()`, `setName()`, `setTable()`, `setValue()`, `writeToManipulation()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $enum | #
`protected mixed` | $default | #
`public static string` | $default_search_filter_class | # Subclass of `SearchFilter` for usage in `DBField::defaultSearchFilter()`. Subclass of `SearchFilter` for usage in `DBField::defaultSearchFilter()`.

### Properties inherited from DBField

`$arrayValue`, `$defaultVal`, `$escape_type`, `$name`, `$tableName`, `$value`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -