SilverStripe 2.4 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
Version: master
  • master
  • 3.1
  • 3.0
  • 2.4
  • tagfield

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • publishers
    • reports
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • installer
  • None
  • PHP
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets

Classes

  • Boolean
  • ComponentSet
  • Currency
  • DatabaseAdmin
  • DataObject
  • DataObjectDecorator
  • DataObjectLog
  • DataObjectSet
  • DataObjectSet_Iterator
  • Date
  • DB
  • DBField
  • Decimal
  • Double
  • Enum
  • Float
  • ForeignKey
  • Hierarchy
  • HTMLText
  • HTMLVarchar
  • Int
  • Money
  • MultiEnum
  • MySQLDatabase
  • MySQLQuery
  • Percentage
  • PrimaryKey
  • SiteTreeDecorator
  • SQLMap
  • SQLMap_Iterator
  • SQLQuery
  • SS_Database
  • SS_Datetime
  • SS_Query
  • SS_Transliterator
  • StringField
  • Text
  • Time
  • Transliterator
  • Varchar
  • Versioned
  • Versioned_Version
  • Year

Interfaces

  • CompositeDBField
  • CurrentPageIdentifier
  • DataObjectInterface

Class DBField

Single field in the database. Every field from the database is represented as a sub-class of DBField.

Multi-value DBField objects

Sometimes you will want to make DBField classes that don't have a 1-1 match to database fields. To do this, there are a number of fields for you to overload. - Overload DBField::writeToManipulation() to add the appropriate references to the INSERT or UPDATE command - Overload DBField::addToQuery() to add the appropriate items to a SELECT query's field list - Add appropriate accessor methods

Subclass Example

The class is easy to overload with custom types, e.g. the MySQL "BLOB" type (http://dev.mysql.com/doc/refman/5.0/en/blob.html).

class Blob extends DBField {
        function requireField() {
                DB::requireField($this->tableName, $this->name, "blob");
 }
}
Object
Extended by ViewableData implements IteratorAggregate
Extended by DBField

Direct known subclasses

Boolean, Date, Year, Decimal, Double, Enum, Float, Int, Money, StringField, Time

Indirect known subclasses

Currency, DBLocale, Varchar, ForeignKey, HTMLText, HTMLVarchar, MultiEnum, Percentage, PrimaryKey, SS_Datetime, Text

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

Methods summary

public
# __construct( mixed $name = null )

Overrides

Object::__construct
public static Object
# create( string $className, mixed $arguments,…, mixed $name = null, mixed $object = null )

Create a DBField object that's not bound to any particular field. Useful for accessing the classes behaviour for other parts of your code.

Create a DBField object that's not bound to any particular field. Useful for accessing the classes behaviour for other parts of your code.

Parameters

$className
string
$class the class name
$arguments,…
mixed
$arguments,... arguments to pass to the constructor
$name
$object

Returns

Object

Overrides

Object::create
public
# setName( mixed $name )

Set the name of this field. The name should never be altered, but it if was never given a name in the first place you can set a name. If you try an alter the name a warning will be thrown.

Set the name of this field. The name should never be altered, but it if was never given a name in the first place you can set a name. If you try an alter the name a warning will be thrown.

public string
# getName( )

Returns the name of this field.

Returns the name of this field.

Returns

string
public mixed
# getValue( )

Returns the value of this field.

Returns the value of this field.

Returns

mixed
public
# setValue( mixed $value, array $record = null )

Set the value on the field. Optionally takes the whole record as an argument, to pick other values.

Set the value on the field. Optionally takes the whole record as an argument, to pick other values.

Parameters

$value
mixed
$value
$record
array
$record
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

Overrides

ViewableData::hasValue
public boolean
# exists( )

Returns

boolean

Overrides

Object::exists
public string
# prepValueForDB( mixed $value )

Return an encoding of the given value suitable for inclusion in a SQL statement. If necessary, this should include quotes.

Return an encoding of the given value suitable for inclusion in a SQL statement. If necessary, this should include quotes.

Parameters

$value
mixed
$value mixed The value to check

Returns

string
The encoded value
public
# writeToManipulation( array & $manipulation )

Prepare the current field for usage in a database-manipulation (works on a manipulation reference).

Prepare the current field for usage in a database-manipulation (works on a manipulation reference).

Make value safe for insertion into a SQL SET statement by applying addslashes() - can also be used to apply special SQL-commands to the raw value (e.g. for GIS functionality). DBField::prepValueForDB()

Parameters

$manipulation
array
$manipulation
public
# addToQuery( SS_Query & $query )

Add custom query parameters for this field, mostly SELECT statements for multi-value fields.

Add custom query parameters for this field, mostly SELECT statements for multi-value fields.

By default, the ORM layer does a SELECT <tablename>.* which gets you the default representations of all columns.

Parameters

$query
SS_Query
$query
public
# setTable( mixed $tableName )
public string
# forTemplate( )

Returns

string
public
# HTMLATT( )
public
# URLATT( )
public
# RAWURLATT( )
public
# ATT( )
public
# RAW( )
public
# JS( )
public
# HTML( )
public
# XML( )
public string
# LowerCase( )

Converts the current value for this Enum DBField to lowercase.

Converts the current value for this Enum DBField to lowercase.

Returns

string
public string
# UpperCase( )

Converts the current value for this Enum DBField to uppercase.

Converts the current value for this Enum DBField to uppercase.

Returns

string
public
# nullValue( )

Returns the value to be set in the database to blank this field. Usually it's a choice between null, 0, and ''

Returns the value to be set in the database to blank this field. Usually it's a choice between null, 0, and ''

public
# saveInto( mixed $dataObject )

Saves this field to the given data object.

Saves this field to the given data object.

public FormField
# scaffoldFormField( string $title = 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

Returns

FormField

Used by

FormScaffolder
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
public SearchFilter
# defaultSearchFilter( mixed $name = false )

Returns

SearchFilter
abstract public
# requireField( )

Add the field to the underlying database.

Add the field to the underlying database.

public
# debug( )

Methods inherited from ViewableData

ATT_val(), BaseHref(), CSSClasses(), CurrentMember(), CurrentPage(), Debug(), Even(), EvenOdd(), First(), FirstLast(), HasPerm(), IsAjax(), JS_val(), Last(), Me(), Middle(), MiddleString(), Modulus(), MultipleOf(), Odd(), Pos(), RAW_val(), SQL_val(), ThemeDir(), 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(), 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 $value
#
protected mixed $tableName
#
protected mixed $name
#
protected mixed $arrayValue
#
public static string $escape_type
#

The escape type for this field when inserted into a template - either "xml" or "raw".

The escape type for this field when inserted into a template - either "xml" or "raw".

public static string $default_search_filter_class
#

Subclass of SearchFilter for usage in DBField::defaultSearchFilter().

Subclass of SearchFilter for usage in DBField::defaultSearchFilter().

protected mixed $defaultVal
#

mixed Default-value in the database. Might be overridden on DataObject-level, but still useful for setting defaults on already existing records after a db-build.

mixed Default-value in the database. Might be overridden on DataObject-level, but still useful for setting defaults on already existing records after a db-build.

Properties inherited from ViewableData

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

Properties inherited from Object

$class, $extension_instances, $extensions

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.
blog comments powered by Disqus
SilverStripe 2.4 API Docs API documentation generated by ApiGen 2.8.0