Class DataObject
A single database record & abstract class for the data-access-model.
Extensions and Decorators
See Extension and DataObjectDecorator.
Permission Control
Object-level access control by Permission. Permission codes are
arbitrary strings which can be selected on a group-by-group basis.
class Article extends DataObject implements PermissionProvider { static $api_access = true; public function canView($member = false) { return Permission::check('ARTICLE_VIEW'); } public function canEdit($member = false) { return Permission::check('ARTICLE_EDIT'); } public function canDelete() { return Permission::check('ARTICLE_DELETE'); } public function canCreate() { return Permission::check('ARTICLE_CREATE'); } public function providePermissions() { return array( 'ARTICLE_VIEW' => 'Read an article object', 'ARTICLE_EDIT' => 'Edit an article object', 'ARTICLE_DELETE' => 'Delete an article object', 'ARTICLE_CREATE' => 'Create an article object', ); } }
Object-level access control by Group membership:
class Article extends DataObject { static $api_access = true; public function canView($member = false) { if(!$member) $member = Member::currentUser(); return $member->inGroup('Subscribers'); } public function canEdit($member = false) { if(!$member) $member = Member::currentUser(); return $member->inGroup('Editors'); } // ... }
If any public method on this class is prefixed with an underscore, the
results are cached in memory through ViewableData::cachedCall().
- Object
-
ViewableData
implements
IteratorAggregate
-
DataObject
implements
DataObjectInterface,
i18nEntityProvider
Direct known subclasses
Address,
BookingOrder,
DocumentHaving,
DocumentItem,
DocumentPage_File,
DocumentType,
EditableFormField,
EditableOption,
Email_BounceRecord,
Epitaph,
FaqQuestion,
File,
BookingOrder_StatusLog,
FlowerGarden,
FlowerGarden_Size,
Group,
GuestbookEntry,
Import1CLog,
Import1CLog_File,
Import1CLog_Item,
Import1CLog_Task,
ImportCatalog1C_PriceType,
ImportCatalog1C_ProductProp,
BookingPaymentMethod,
LoginAttempt,
LogItem,
Material3D_File,
MediawebPage_File,
MediawebPage_Photo,
Member,
MemberPassword,
MonumentGalleryItem,
MonumentPhotoGallery,
Newsletter,
BookingService,
Newsletter_Recipient,
Newsletter_SentRecipient,
NewsletterEmailBlacklist,
NewsletterType,
Notification,
Order,
Order_StatusLog,
OrderDataObject,
OrderItem,
PageComment,
CatalogFilter,
Payment,
PaymentMethod,
PaymentType,
Permission,
PermissionRole,
PermissionRoleCode,
Person,
PhotoAlbumItem,
Polishing,
Poll,
CustomMenuHolder,
PollAnswer,
PortraitType,
ProductImportLog,
ProductImportLog_Item,
ProductParam,
ProductParamValue,
ProductVariation,
QueuedEmail,
RatePeriod,
RatingDataObject,
CustomMenuItem,
RealtyImportLog,
RealtyImportLog_Item,
RedirectEntry,
RegionRestriction,
RelatedPageLink,
RoomOrder,
RoomOrderPerson,
RoomRate,
ServiceOrder,
ShippingMethod,
DataObjectFileTracking,
SimpleOrderData,
SiteConfig,
SiteTree,
SocleSection,
SubmittedForm,
SubmittedFormField,
Subsite,
SubsiteDomain,
Texture3D_File,
UnsubscribeRecord,
DocumentDirection,
UserDefinedForm_EmailRecipient,
VAT,
VideoCategory,
VideoEntry,
VKNotificationQueue,
WebylonWidget_Item,
Widget,
WidgetArea
Indirect known subclasses
AdditionalMenuWidget,
AdditionalMenuWidget_Item,
BookingAdminPage,
PhotoGalleryPage,
PhotoGalleryWidget,
PollSidebarWidget,
PriceListWidget,
Product,
ProductSearchPage,
ProfilePage,
PublHolder,
Publication,
PublicationWidget,
BookingPage,
RedirectorPage,
RegistrationPage,
Room,
RoomCatalog,
RoomService,
RoomServiceOrder,
SberbankPayment,
SearchWidget,
SeparateHomepageWidget,
SeparateSidebarWidget,
ButtonsBlockHomepageWidget,
SidebarWidget,
SidebarWidgetArea,
SimpleOrderForm,
SimpleOrderPage,
SliderHomepageWidget,
SliderHomepageWidget_Item,
Socle,
SocleSize,
SpecialCatalog,
SpecialCatalogHomepageWidget,
ButtonsBlockHomepageWidget_Item,
SpecialCatalogSidebarWidget,
StartCatalog,
SubmittedFileField,
SubscribeForm,
SubscribeWidget,
SubsectionMenuWidget,
Subsite_Template,
SubsitesSelectorPage,
SubsitesVirtualPage,
TableShippingMethod,
CallBackWidget,
TableShippingRate,
TextAnonsWidget,
TextAnonsWidget_Item,
TextBlockHomepageWidget,
TextBlockSidebarWidget,
UnitellerPayment,
UserDefinedForm,
VideoBankPage,
VideoFile,
VirtualPage,
CarouselHomepageWidget,
VirtualProduct,
WeatherSidebarWidget,
WebylonWidget,
WebylonWidgetArea,
WeightTableShippingMethod,
WeightTableShippingRate,
YaMoneyPayment,
YandexMapsHomepageWidget,
YandexMapsWidget,
CarouselHomepageWidget_Item,
CartPage,
CartWidget,
Catalog,
AdvancedSliderHomepageWidget,
CatalogFilterSidebarWidget,
CatalogRubricsHomepageWidget,
CheckoutPage,
ChequePayment,
ConsultantWidget,
ContactsBlockWidget,
ContactsPage,
CostTableShippingMethod,
CostTableShippingRate,
CurrencyWidget,
AdvancedSliderHomepageWidget_Item,
CustomPayment,
DocPage,
DocumentsPage,
EditableCheckbox,
EditableCheckboxGroupField,
EditableCountryDropdownField,
EditableDateField,
EditableDateTimeField,
EditableDropdown,
EditableEmailField,
Announcement,
EditableFileField,
EditableFormHeading,
EditableHiddenField,
EditableLiteralField,
EditableMemberListField,
EditableMultipleOptionField,
EditableNumericField,
EditablePhoneField,
EditableRadioField,
EditableSiteAgreementField,
AnnouncementHolder,
EditableSpamProtectionField,
EditableTextField,
EditableTimeField,
ErrorPage,
Event,
EventCalendarWidget,
EventHolder,
FaqHolder,
FAQHomepageWidget,
FaqSection,
AuthFormWidget,
FAQSidebarWidget,
FavoritePage,
FavoriteProductsSidebarWidget,
FeedbackHomepageWidget,
FixedShippingMethod,
FLV,
Folder,
Guestbook,
GuestbookWidget,
HomePage,
BannerWidget,
HomepageWidget,
HomepageWidgetArea,
HouseCatalogSearchWidget,
HTMLBlockHomepageWidget,
HTMLBlockSidebarWidget,
Image,
Image_Cached,
MapObject,
MapObjectGroup,
MapPage,
BannerWidget_Item,
MediawebPage,
MediawebPage_Image,
Monument,
MonumentCatalog,
MonumentForm,
MP3,
NewsArchive,
NewsEntry,
NewsHolder,
NewsHomepageWidget,
BaseObjectCategory,
NewsSidebarWidget,
OrderService,
OrderServiceOrder,
Page,
PageMenuWidget,
PayPalPayment,
PhotoAlbumHomepageWidget,
PhotoAlbumPage,
PhotoGalleryHomepageWidget,
PhotoGalleryHomepageWidget_Item
Methods summary
public static
boolean
|
|
public static
|
#
set_validation_enabled( mixed $enable )
Set whether DataObjects should be validated before they are written. |
public static
array
|
#
database_fields( string $class )
Return the complete map of fields on this object, including Created, LastEdited and ClassName |
public static
array
|
#
custom_database_fields( string $class )
Get all database columns explicitly defined on a class in |
public static
|
#
is_composite_field( mixed $class, mixed $name, mixed $aggregated = true )
Returns the field class if the given db field on the class is a composite field. Will check all applicable ancestor classes and aggregate results. |
public static
|
#
composite_fields( mixed $class, mixed $aggregated = true )
Returns a list of all the composite if the given db field on the class is a composite field. Will check all applicable ancestor classes and aggregate results. |
public static
|
#
disableCMSFieldsExtensions( )
Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by subclasses of SiteTree in a decorator. Call before calling parent::getCMSFields(), and reenable afterwards. |
public static
|
#
enableCMSFieldsExtensions( )
Reenables extendCMSFields() being called on getCMSFields() after it has been disabled by disableCMSFieldsExtensions(). |
public
|
#
__construct( array|null $record = null, boolean $isSingleton = false )
Construct a new DataObject. |
public
|
|
public
|
|
public
|
#
setClassName( string $className )
Set the ClassName attribute. |
public
|
#
newClassInstance( string $newClassName )
Create a new instance of a different class from this object's record. This is useful when dynamically changing the type of an instance. Specifically, it ensures that the instance of the class is a match for the className of the record. Don't set the DataObject->class or DataObject->ClassName property manually before calling this method, as it will confuse change detection. |
public
|
#
defineMethods( )
Adds methods from the extensions. Called by Object::__construct() once per class. |
public
boolean
|
|
public
|
|
public
string
|
#
singular_name( )
Get the user friendly singular name of this DataObject. If the name is not defined (by redefining $singular_name in the subclass), this returns the class name. |
public
string
|
#
i18n_singular_name( )
Get the translated user friendly singular name of this DataObject same as singular_name() but runs it through the translating function |
public
string
|
#
plural_name( )
Get the user friendly plural name of this DataObject If the name is not defined (by renaming $plural_name in the subclass), this returns a pluralised version of the class name. |
public
string
|
#
i18n_plural_name( )
Get the translated user friendly plural name of this DataObject Same as
plural_name but runs it through the translation function Translation string is
in the form: |
public
string
|
|
public
|
|
public
array
|
|
public
|
|
public
|
#
castedUpdate( array $data )
Pass changes as a map, and try to get automatic casting for these fields. Doesn't write to the database. To write the data, use the write() method. |
public
|
#
merge( mixed $rightObj, mixed $priority = 'right', mixed $includeRelations = true, mixed $overwriteWithEmpty = false )
Merges data and relations from another object of same class, without conflict resolution. Allows to specify which dataset takes priority in case its not empty. has_one-relations are just transferred with priority 'right'. has_many and many_many-relations are added regardless of priority. |
public
|
#
forceChange( )
Forces the record to think that all its data has changed. Doesn't write to the database. Only sets fields as changed if they are not already marked as changed. |
protected
A
|
|
protected
|
#
onBeforeWrite( )
Event handler called before writing to the database. You can overload this to clean up or otherwise process data before writing it to the database. Don't forget to call parent::onBeforeWrite(), though! |
protected
|
#
onAfterWrite( )
Event handler called after writing to the database. You can overload this to act upon changes made to the data after it is written. $this->changed will have a record database. Don't forget to call parent::onAfterWrite(), though! |
protected
|
#
onBeforeDelete( )
Event handler called before deleting from the database. You can overload this to clean up or otherwise process data before delete this record. Don't forget to call parent::onBeforeDelete(), though! |
protected
|
|
public
|
#
populateDefaults( )
Load the default values in from the self::$defaults array. Will traverse the defaults of the current class and all its parent classes. Called by the constructor when creating new records. |
public
integer
|
#
write( boolean $showDebug = false, boolean $forceInsert = false, boolean $forceWrite = false, boolean $writeComponents = false )
Writes all changes to this object to the database. |
public
|
#
writeComponents( mixed $recursive = false )
Write the cached components to the database. Cached components could refer to two different instances of the same record. |
public
integer
|
#
writeWithoutVersion( )
Perform a write without affecting the version table. On objects without versioning. |
public
|
|
public static
|
|
public
array
|
#
getClassAncestry( )
Get the class ancestry, including the current class name. The ancestry will be returned as an array of class names, where the 0th element will be the class that inherits directly from DataObject, and the last element will be the current class. |
public
|
#
getComponent( string $componentName )
Return a component object from a one to one relationship, as a DataObject. If no component is available, an 'empty component' will be returned. |
public
|
#
getComponents( string $componentName, string $filter = "", string|array $sort = "", string $join = "", string|array $limit = "" )
Returns a one-to-many component, as a ComponentSet. |
public
|
#
getComponentsQuery( string $componentName, string $filter = "", string|array $sort = "", string $join = "", string|array $limit = "" )
Get the query object for a $has_many Component. |
public
string
|
#
getRemoteJoinField( string $component, string $type = 'has_many' )
Tries to find the database key on another object that is used to store a relationship to this class. If no join field can be found it defaults to 'ParentID'. |
public
|
#
setComponent( string $componentName,
Sets the component of a relationship. |
public
|
#
getManyManyComponents( string $componentName, mixed $filter = "", mixed $sort = "", mixed $join = "", mixed $limit = "" )
Returns a many-to-many component, as a ComponentSet. |
public
|
#
getManyManyComponentsQuery( string $componentName, string $filter = "", string|array $sort = "", string $join = "", string|array $limit = "" )
Get the query object for a $many_many Component. Use DataObjectSet->setComponentInfo() to attach metadata to the resultset you're
building with this query. Use DataObject->buildDataObjectSet() to
build a set out of the |
public
string
|
#
getManyManyJoin( string $componentName, string $baseTable )
Pull out a join clause for a many-many relationship. |
public
|
|
public
|
|
public
|
#
RelationshipAggregate( mixed $object = null, mixed $relationship = '', mixed $filter = '' )
Return an relationship aggregate object. A relationship aggregate does the same thing as an aggregate object, but operates on a has_many rather than directly on the type specified |
public
string|array
|
|
public
string|array
|
#
belongs_to( string $component = null, boolean $classOnly = true )
Returns the class of a remote belongs_to relationship. If no component is specified a map of all components and their class name will be returned. |
public
array
|
|
public
string|array
|
|
public
array
|
#
many_many_extraFields( string $component = null )
Return the many-to-many extra fields specification. |
public
array
|
|
public
array
|
#
database_extensions( mixed $class )
This returns an array (if it exists) describing the database extensions that are required, or false if none |
public
|
#
getDefaultSearchContext( )
Generates a SearchContext to be used for building and processing a generic search form for properties on this object. |
public
|
#
scaffoldSearchFields( array $_params = null )
Determine which properties on the DataObject are searchable, and map them to
their default |
public
|
#
scaffoldFormFields( array $_params = null )
Scaffold a simple edit form for all properties on this dataobject, based on
default |
public
|
#
getCMSFields( array $params = null )
Centerpiece of every data administration interface in Silverstripe, which
returns a |
public
an
|
#
getCMSActions( )
need to be overload by solid dataobject, so that the customised actions of that dataobject, including that dataobject's decorator customised actions could be added to the EditForm. |
public
|
#
getFrontEndFields( array $params = null )
Used for simple frontend forms without relation editing or |
public
mixed
|
#
getField( string $field )
Gets the value of a field. Called by |
public
array
|
|
public
array
|
#
getChangedFields( boolean $databaseFieldsOnly = false, integer $changeLevel = 1 )
Return the fields that have changed. |
public
boolean
|
#
isChanged( string $fieldName = null, integer $changeLevel = 1 )
Uses |
public
|
#
setField( string $fieldName, mixed $val )
Set the value of the field Called by |
public
|
#
setCastedField( string $fieldName, mixed $val )
Set the value of the field, using a casting object. This is useful when you aren't sure that a date is in SQL format, for example. setCastedField() can also be used, by forms, to set related data. For example, uploaded images can be saved into the Image table. |
public
boolean
|
|
public
boolean
|
|
public
string
|
#
hasOwnTableDatabaseField( string $field )
Returns the field type of the given field, if it belongs to this class, and not a parent. Note that the field type will not include constructor arguments in round brackets, only the classname. |
public static
boolean
|
#
has_own_table( string $dataClass )
Returns true if given class has its own table. Uses the rules for whether the table should exist rather than actually looking in the database. |
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
string
|
|
public
|
#
dbObject( string $fieldName )
Return the DBField object that represents the given field. This works
similarly to obj() with 2 key differences: |
public
|
|
public
String
|
#
getReverseAssociation( mixed $className )
Temporary hack to return an association name, based on class, to get around the mangle of having to deal with reverse lookup of relationships to determine autogenerated foreign keys. |
public
|
|
public
|
#
extendedSQL( string $filter = "", string|array $sort = "", string|array $limit = "", string $join = "", string $having = "" )
Like |
public static
mixed
|
|
public
mixed
|
#
instance_get( string $filter = "", string $sort = "", string $join = "", string $limit = "", string $containerClass = "DataObjectSet" )
The internal function that actually performs the querying for get(). DataObject::get("Table","filter") is the same as singleton("Table")->instance_get("filter") |
public
mixed
|
#
buildDataObjectSet(
Take a database |
public static
|
|
public
|
#
flushCache( boolean $persistant = true )
Flush the cached results for all relations (has_one, has_many, many_many) Also clears any cached aggregate data |
public static
|
|
public static
|
|
public
|
|
public static
|
|
public
|
|
public
|
#
databaseIndexes( )
Return the database indexes on this table. This array is indexed by the name of the field with the index, and the value is the type of index. |
public
|
|
public
|
#
requireDefaultRecords( )
Add default records to database. This function is called whenever the database is built, after the database tables have all been created. Overload this to add default records when the database is built, but make sure you call parent::requireDefaultRecords(). |
public
|
|
public
|
|
public
|
#
inheritedDatabaseFields( )
Returns fields bu traversing the class heirachy in a bottom-up direction. |
public
array
|
#
searchableFields( )
Get the default searchable fields for this object, as defined in the $searchable_fields list. If searchable fields are not defined on the data object, uses a default selection of summary fields. |
public
array|string
|
#
fieldLabels( boolean $includerelations = true )
Get any user defined searchable fields labels that exist. Allows overriding of default field names in the form interface actually presented to the user. |
public
string
|
#
fieldLabel( string $name )
Get a human-readable label for a single field, see |
public
array
|
|
public
array
|
|
public
boolean
|
|
public static
|
#
set_context_obj( mixed $obj )
Sets a 'context object' that can be used to provide hints about how to process a particular get / get_one request. In particular, DataObjectDecorators can use this to amend queries more effectively. Care must be taken to unset the context object after you're done with it, otherwise you will have a stale context, which could cause horrible bugs. |
public static
|
|
public static
|
|
public static
|
|
public
array
|
#
provideI18nEntities( )
Collect all static properties on the object which contain natural language, and need to be translated. The full entity name is composed from the class name and a custom identifier. |
public
boolean
|
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(),
escapeTypeForField(),
getIterator(),
getSecurityID(),
getXMLValues(),
i18nLocale(),
iteratorProperties(),
obj(),
renderWith(),
setCustomisedObj()
Methods inherited from Object
__call(),
__toString(),
__wakeup(),
addMethodsFrom(),
addStaticVars(),
addWrapperMethod(),
add_extension(),
add_static_var(),
allMethodNames(),
cacheToFile(),
cacheToFileWithArgs(),
clearCache(),
combined_static(),
create(),
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
public static
string
|
$singular_name |
#
Human-readable singular name. |
public static
string
|
$plural_name |
#
Human-readable pluaral name |
public static
boolean
|
$api_access |
#
Allow API access to this object? |
public static
array
|
$cache_has_own_table | |
public static
array
|
$cache_has_own_table_field | |
public
boolean
|
$destroyed |
#
True if this DataObject has been destroyed. |
protected
array
|
$record |
#
Data stored in this objects database record. An array indexed by fieldname. |
protected
array
|
$original |
#
The database record (in the same format as $record), before any changes. |
protected
array
|
$components |
#
The one-to-one, one-to-many and many-to-one components indexed by component name. |
protected
boolean
|
$brokenOnDelete |
#
Used by onBeforeDelete() to ensure child classes call parent::onBeforeDelete() |
protected
boolean
|
$brokenOnWrite |
#
Used by onBeforeWrite() to ensure child classes call parent::onBeforeWrite() |
protected static
array
|
$ancestry |
#
A cache used by getClassAncestry() |
protected
array
|
$componentCache |
#
A cache used by component getting classes |
protected static
array
|
$cache_get_one |
#
A cache used by get_one. |
public static
array
|
$db |
#
Database field definitions. This is a map from field names to field type. The field type should be a class that extends . |
public static
array
|
$casting |
#
Use a casting object for a field. This is a map from field name to class name of the casting object. |
public static
array
|
$create_table_options |
#
Specify custom options for a CREATE TABLE call. Can be used to specify a
custom storage engine for specific database table. All options have to be keyed
for a specific database implementation, identified by their class name
(extending from |
public static
array
|
$indexes |
#
If a field is in this array, then create a database index on that field. This is a map from fieldname to index type. See SS_Database->requireIndex() and custom subclasses for details on the array notation. |
public static
array
|
$defaults |
#
Inserts standard column-values when a DataObject is instanciated. Does not
insert default records |
public static
array
|
$default_records |
#
Multidimensional array which inserts default data into the database on a db/build-call as long as the database-table is empty. Please use this only for simple constructs, not for SiteTree-Objects etc. which need special behaviour such as publishing and ParentNodes. |
public static
array
|
$has_one |
#
One-to-zero relationship defintion. This is a map of component name to data
type. In order to turn this into a true one-to-one relationship you can add a
|
public static
array
|
$belongs_to |
#
A meta-relationship that allows you to define the reverse side of a |
public static
array
|
$has_many |
#
This defines a one-to-many relationship. It is a map of component name to the remote data class. |
public static
array
|
$many_many |
#
many-many relationship definitions. This is a map from component name to data type. |
public static
array
|
$many_many_extraFields |
#
Extra fields to include on the connecting many-many table. This is a map from field name to field type. |
public static
array
|
$belongs_many_many |
#
The inverse side of a many-many relationship. This is a map from component name to data type. |
public static
string
|
$default_sort |
#
The default sort expression. This will be inserted in the ORDER BY clause of a SQL query if no other sort expression is provided. |
public static
mixed
|
$searchable_fields |
#
Default list of fields that can be scaffolded by the ModelAdmin search interface. |
public static
mixed
|
$field_labels |
#
User defined labels for searchable_fields, used to override default display in the search form. |
public static
mixed
|
$summary_fields |
#
Provides a default list of fields to be used by a 'summary' view of this object. |
public static
mixed
|
$allowed_actions |
#
Provides a list of allowed methods that can be called via RESTful api. |
Properties inherited from ViewableData
$customisedObject,
$default_cast,
$failover,
$iteratorPos,
$iteratorTotalItems