Table of Contents

Introduction

These are the data-types that you can use when defining your data objects. They are all subclasses of DBField. See also form-field-types, which lists all fields you can use to put these data types in forms. See 2-extending-a-basic-site for introducing their usage.

Types

  • Varchar: A variable-length string of up to 255 characters, designed to store raw text
  • Text: A variable-length string of up to 2 megabytes, designed to store raw text
  • HTMLVarchar: A variable-length string of up to 255 characters, designed to store HTML
  • HTMLText: A variable-length string of up to 2 megabytes, designed to store HTML
  • Enum: An enumeration of a set of strings.
  • Boolean: An boolean (true/false) field.
  • Int: An integer field.
  • Decimal/Float/Double: A decimal number.
  • Currency: A number with 2 decimal points of precision, designed to store currency values.
  • Percentage: A decimal number between 0 and 1 that represents a percentage.

HTMLText vs. Text, and HTMLVarchar vs. Varchar

The database field types HTMLVarchar and Varchar are exactly the same in the database. However, the templating engine knows to escape the Varchar field and not the HTMLVarchar field. So, it's important you use the right field if you don't want to be putting $FieldType.XML everywhere.

If you're going to put HTML content into the field, please use the field type with the HTML prefix. Otherwise, you're going to risk double-escaping your data, forgetting to escape your data, and generally creating a confusing situation.

Usage

  • See datamodel for information about database schemas implementing these types
  • See objectmodel for information about casting values to these types
 
data-types.txt · Last modified: 2010/05/05 23:38 (external edit)

Please use comments for notes, tips and corrections about the described functionality.
Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Creative Commons LicenseSilverStripe Documentation by SilverStripe is licensed under a Creative Commons Attribution 3.0 New Zealand License.
Based on a work at doc.silverstripe.com
Recent changes RSS feed Driven by DokuWiki