BaseElementModel

Type
Abstract Class
Namespace
Craft
Inherits
Craft\BaseElementModel » Craft\BaseModel » CModel (opens new window) » CComponent (opens new window)
Implements
ArrayAccess (opens new window), IteratorAggregate (opens new window)
Extended by
Craft\AssetFileModel, Craft\BaseEntryRevisionModel, Craft\CategoryModel, Craft\EntryDraftModel, Craft\EntryModel, Craft\EntryVersionModel, Craft\GlobalSetModel, Craft\MatrixBlockModel, Craft\TagModel, Craft\UserModel
Since
1.0

Base element model class.

See also http://craftcms.com

View source (opens new window)

# Protected Properties

Property Description
$classSuffix string (opens new window)
$elementType
$strictAttributes boolean (opens new window) – Whether this model should be strict about only allowing values to be set on defined attributes

# $elementType

Signature

protected  $elementType = null

# Public Methods

Method Description
__call() Magic __call() method, used for chain-setting attribute values.
__construct() Constructor
__get() Getter
__isset() Treats custom fields as properties.
__set() PHP setter magic method.
__toString() Use the element's title as its string representation.
__unset() (opens new window) Sets a component property to be null.
addError() (opens new window) Adds a new error to the specified attribute.
addErrors() (opens new window) Adds a list of errors.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
attributeLabels() Returns the attribute labels.
attributeNames() Returns the list of this model's attribute names.
behaviors() (opens new window) Returns a list of behaviors that this model should behave as.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
clearErrors() (opens new window) Removes errors for all attributes or a single attribute.
copy() Returns a copy of this model.
createValidators() (opens new window) Creates validator objects based on the specification in {@link rules}.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
evaluateExpression() (opens new window) Evaluates a PHP expression or callback under the context of this component.
generateAttributeLabel() Generates a user friendly attribute label.
getAllErrors() Returns all errors in a single, flattened list, devoid of attribute names.
getAncestors() Returns the element's ancestors.
getAttribute() Gets an attribute’s value.
getAttributeConfigs() Returns this model's normalized attribute configs.
getAttributeLabel() (opens new window) Returns the text label for the specified attribute.
getAttributes() Returns an array of attribute values.
getChildren() Returns the element's children.
getClassHandle() Get the class name, sans namespace and suffix.
getContent() Returns the content for the element.
getContentFromPost() Returns the raw content from the post data, before it was passed through {@link prepValueFromPost()}.
getContentPostLocation() Returns the location in POST that the content was pulled from.
getContentTable() Returns the name of the table this element's content is stored in.
getCpEditUrl() Returns the element's CP edit URL.
getDescendants() Returns the element's descendants.
getEagerLoadedElements() Returns some eager-loaded elements on a given handle.
getElementType() Returns the type of element this is.
getError() (opens new window) Returns the first error of the specified attribute.
getErrors() (opens new window) Returns the errors for all attribute or a single attribute.
getEventHandlers() (opens new window) Returns the list of attached event handlers for an event.
getExtraAttributeNames() Returns a list of the names of the extra attributes that have been saved on this model, if it's not strict.
getFieldColumnPrefix() Returns the field column prefix this element's content uses.
getFieldContext() Returns the field context this element's content uses.
getFieldLayout() Returns the field layout used by this element.
getFieldValue() Returns the prepped content for a given field.
getHasFreshContent() Returns whether the element’s content is "fresh" (unsaved and without validation errors).
getIterator() (opens new window) Returns an iterator for traversing the attributes in the model.
getLink() Returns an anchor pre-filled with this element's URL and title.
getLocales() Returns the locale IDs this element is available in.
getNext() Returns the next element relative to this one, from a given set of criteria.
getNextSibling() Returns the element's next sibling.
getParent() Get the element's parent.
getParents() Returns a new ElementCriteriaModel prepped to return this element's same-type parents.
getPrev() Returns the previous element relative to this one, from a given set of criteria.
getPrevSibling() Returns the element's previous sibling.
getRawContent() Returns the raw content saved on this entity.
getRef() Returns the reference string to this element.
getSafeAttributeNames() (opens new window) Returns the attribute names that are safe to be massively assigned.
getScenario() (opens new window) Returns the scenario that this model is used in.
getSiblings() Returns all of the element's siblings.
getStatus() Returns the element's status.
getThumbUrl() Returns the URL to the element's thumbnail, if there is one.
getTitle() Returns the element's title.
getTotalDescendants() Returns the total number of descendants that the element has.
getUrl() Returns the element's full URL.
getUrlFormat() Returns the URL format used to generate this element's URL.
getValidatorList() (opens new window) Returns all the validators declared in the model.
getValidators() (opens new window) Returns the validators applicable to the current {@link scenario}.
hasDescendants() Returns whether the element has descendants.
hasEagerLoadedElements() Returns whether elements have been eager-loaded with a given handle.
hasErrors() (opens new window) Returns a value indicating whether there is any validation error.
hasEvent() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasProperty() (opens new window) Determines whether a property is defined.
isAncestorOf() Returns whether this element is an ancestor of another one.
isAttributeRequired() (opens new window) Returns a value indicating whether the attribute is required.
isAttributeSafe() (opens new window) Returns a value indicating whether the attribute is safe for massive assignments.
isChildOf() Returns whether this element is a direct child of another one.
isDescendantOf() Returns whether this element is a descendant of another one.
isEditable() Returns whether the current user can edit the element.
isNextSiblingOf() Returns whether this element is the direct next sibling of another one.
isParentOf() Returns whether this element is a direct parent of another one.
isPrevSiblingOf() Returns whether this element is the direct previous sibling of another one.
isSiblingOf() Returns whether this element is a sibling of another one.
offsetExists() Treats custom fields as array offsets.
offsetGet() (opens new window) Returns the element at the specified offset.
offsetSet() (opens new window) Sets the element at the specified offset.
offsetUnset() (opens new window) Unsets the element at the specified offset.
onAfterConstruct() (opens new window) This event is raised after the model instance is created by new operator.
onAfterValidate() (opens new window) This event is raised after the validation is performed.
onBeforeValidate() (opens new window) This event is raised before the validation is performed.
onUnsafeAttribute() (opens new window) This method is invoked when an unsafe attribute is being massively assigned.
populateModel() Populates a new model instance with a given set of attributes.
populateModels() Mass-populates models based on an array of attribute arrays.
raiseEvent() (opens new window) Raises an event.
rules() Returns this model's validation rules.
setAttribute() Sets an attribute's value.
setAttributes() Sets multiple attribute values at once.
setContent() Sets the content for the element.
setContentFromPost() Sets the content from post data, calling prepValueFromPost() on the field types.
setContentPostLocation() Sets the location in POST that the content was pulled from.
setEagerLoadedElements() Sets some eager-loaded elements on a given handle.
setNext() Sets the default next element.
setParent() Sets the element's parent.
setPrev() Sets the default previous element.
setRawPostContent() Sets a field’s raw post content.
setScenario() (opens new window) Sets the scenario for the model.
unsetAttributes() (opens new window) Sets the attributes to be null.
validate() Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get logged to the craft/storage/runtime/logs folder with a level of LogLevel::Warning.

# __get()

Signature

public mixed __get ( $name )

# __isset()

Treats custom fields as properties.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean __isset ( $name )

# __toString()

Use the element's title as its string representation.

View source (opens new window)

Returns

string (opens new window)

Signature

public string __toString ( )

# getAncestors()

Signature

public Craft\ElementCriteriaModel getAncestors ( $dist = null )

# getAttribute()

Gets an attribute’s value.

BaseModel::getAttribute()

View source (opens new window)

Arguments

Returns

mixed

Signature

public mixed getAttribute ( $name, $flattenValue = false )

# getChildren()

Returns the element's children.

View source (opens new window)

Arguments

  • $field (mixed) – If this function is being used in the deprecated relationship-focused way, $field defines which field (if any) to limit the relationships by.

Returns

Craft\ElementCriteriaModel

Signature

public Craft\ElementCriteriaModel getChildren ( $field = null )

# getContent()

Returns the content for the element.

View source (opens new window)

Returns

Craft\ContentModel

Signature

public Craft\ContentModel getContent ( )

# getContentFromPost()

Returns the raw content from the post data, before it was passed through {@link prepValueFromPost()}.

View source (opens new window)

Returns

array (opens new window)

Signature

public array getContentFromPost ( )

# getContentPostLocation()

Returns the location in POST that the content was pulled from.

View source (opens new window)

Returns

string (opens new window), null (opens new window)

Signature

public string, null getContentPostLocation ( )

# getContentTable()

Returns the name of the table this element's content is stored in.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getContentTable ( )

# getCpEditUrl()

Signature

public string, false getCpEditUrl ( )

# getDescendants()

Signature

public Craft\ElementCriteriaModel getDescendants ( $dist = null )

# getEagerLoadedElements()

Returns some eager-loaded elements on a given handle.

View source (opens new window)

Arguments

Returns

Craft\BaseElementModel[], null (opens new window) – The eager-loaded elements, or null

Signature

public Craft\BaseElementModel[], null getEagerLoadedElements ( $handle )

# getElementType()

Returns the type of element this is.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getElementType ( )

# getFieldColumnPrefix()

Returns the field column prefix this element's content uses.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getFieldColumnPrefix ( )

# getFieldContext()

Returns the field context this element's content uses.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getFieldContext ( )

# getFieldLayout()

Returns the field layout used by this element.

View source (opens new window)

Returns

Craft\FieldLayoutModel, null (opens new window)

Signature

public Craft\FieldLayoutModel, null getFieldLayout ( )

# getFieldValue()

Returns the prepped content for a given field.

View source (opens new window)

Arguments

Returns

mixed

Throws

Signature

public mixed getFieldValue ( $fieldHandle )

# getHasFreshContent()

Returns whether the element’s content is "fresh" (unsaved and without validation errors).

View source (opens new window)

Returns

boolean (opens new window) – Whether the element’s content is fresh

Signature

public boolean getHasFreshContent ( )

Returns an anchor pre-filled with this element's URL and title.

View source (opens new window)

Returns

\Twig_Markup

Signature

public \Twig_Markup getLink ( )

# getLocales()

Returns the locale IDs this element is available in.

View source (opens new window)

Returns

array (opens new window)

Signature

public array getLocales ( )

# getNext()

Returns the next element relative to this one, from a given set of criteria.

View source (opens new window)

Arguments

  • $criteria (mixed)

Returns

Craft\ElementCriteriaModel, null (opens new window)

Signature

public Craft\ElementCriteriaModel, null getNext ( $criteria = false )

# getNextSibling()

Signature

public Craft\BaseElementModel, null getNextSibling ( )

# getParent()

Signature

public Craft\BaseElementModel, null getParent ( )

# getParents()

DEPRECATED

Deprecated Deprecated in 1.3. Use the relatedTo (opens new window) param instead.

Returns a new ElementCriteriaModel prepped to return this element's same-type parents.

View source (opens new window)

Arguments

  • $field (mixed)

Returns

Craft\ElementCriteriaModel

Signature

public Craft\ElementCriteriaModel getParents ( $field = null )

# getPrev()

Returns the previous element relative to this one, from a given set of criteria.

View source (opens new window)

Arguments

  • $criteria (mixed)

Returns

Craft\ElementCriteriaModel, null (opens new window)

Signature

public Craft\ElementCriteriaModel, null getPrev ( $criteria = false )

# getPrevSibling()

Returns the element's previous sibling.

View source (opens new window)

Returns

Craft\BaseElementModel, null (opens new window)

Signature

public Craft\BaseElementModel, null getPrevSibling ( )

# getRawContent()

DEPRECATED

Deprecated Deprecated in 2.0. Use {@link getContent()} instead.

Returns the raw content saved on this entity. This is now deprecated. Use getContent() to get the ContentModel instead.

View source (opens new window)

Arguments

Returns

mixed

Signature

public mixed getRawContent ( $fieldHandle = null )

# getRef()

Returns the reference string to this element.

View source (opens new window)

Returns

string (opens new window), null (opens new window)

Signature

public string, null getRef ( )

# getSiblings()

Returns all of the element's siblings.

View source (opens new window)

Returns

Craft\ElementCriteriaModel

Signature

public Craft\ElementCriteriaModel getSiblings ( )

# getStatus()

Signature

public string, null getStatus ( )

# getThumbUrl()

Returns the URL to the element's thumbnail, if there is one.

View source (opens new window)

Arguments

Returns

string (opens new window), null (opens new window)

Signature

public string, null getThumbUrl ( $size = null )

# getTitle()

Returns the element's title.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getTitle ( )

# getTotalDescendants()

Returns the total number of descendants that the element has.

View source (opens new window)

Returns

boolean (opens new window)

Signature

public boolean getTotalDescendants ( )

# getUrl()

Returns the element's full URL.

View source (opens new window)

Returns

string (opens new window)

Signature

public string getUrl ( )

# getUrlFormat()

Returns the URL format used to generate this element's URL.

View source (opens new window)

Returns

string (opens new window), null (opens new window)

Signature

public string, null getUrlFormat ( )

# hasDescendants()

Returns whether the element has descendants.

View source (opens new window)

Returns

boolean (opens new window)

Signature

public boolean hasDescendants ( )

# hasEagerLoadedElements()

Returns whether elements have been eager-loaded with a given handle.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether elements have been eager-loaded with the given handle

Signature

public boolean hasEagerLoadedElements ( $handle )

# isAncestorOf()

Returns whether this element is an ancestor of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isAncestorOf ( Craft\BaseElementModel $element )

# isChildOf()

Returns whether this element is a direct child of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isChildOf ( Craft\BaseElementModel $element )

# isDescendantOf()

Returns whether this element is a descendant of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isDescendantOf ( Craft\BaseElementModel $element )

# isEditable()

Returns whether the current user can edit the element.

View source (opens new window)

Returns

boolean (opens new window)

Signature

public boolean isEditable ( )

# isNextSiblingOf()

Returns whether this element is the direct next sibling of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isNextSiblingOf ( Craft\BaseElementModel $element )

# isParentOf()

Returns whether this element is a direct parent of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isParentOf ( Craft\BaseElementModel $element )

# isPrevSiblingOf()

Returns whether this element is the direct previous sibling of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isPrevSiblingOf ( Craft\BaseElementModel $element )

# isSiblingOf()

Returns whether this element is a sibling of another one.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isSiblingOf ( Craft\BaseElementModel $element )

# offsetExists()

Treats custom fields as array offsets.

View source (opens new window)

Arguments

  • $offset (mixed)

Returns

boolean (opens new window)

Signature

public boolean offsetExists ( $offset )

# populateModel()

Populates a new model instance with a given set of attributes.

BaseModel::populateModel()

View source (opens new window)

Arguments

  • $values (mixed)

Returns

Craft\BaseModel

Signature

public static Craft\BaseModel populateModel ( $values )

# setContent()

Sets the content for the element.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

public null setContent ( $content )

# setContentFromPost()

Sets the content from post data, calling prepValueFromPost() on the field types.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

public null setContentFromPost ( $content )

# setContentPostLocation()

Sets the location in POST that the content was pulled from.

View source (opens new window)

Arguments

  • $contentPostLocation

Returns

string (opens new window), null (opens new window)

Signature

public string, null setContentPostLocation ( $contentPostLocation )

# setEagerLoadedElements()

Sets some eager-loaded elements on a given handle.

View source (opens new window)

Arguments

Signature

public void setEagerLoadedElements ( $handle, $elements )

# setNext()

Signature

public null setNext ( $element )

# setParent()

Signature

public null setParent ( $parent )

# setPrev()

Sets the default previous element.

View source (opens new window)

Arguments

Signature

public void setPrev ( $element )

# setRawPostContent()

Sets a field’s raw post content.

View source (opens new window)

Arguments

Signature

public void setRawPostContent ( $handle, $value )

# Protected Methods

Method Description
afterConstruct() (opens new window) This method is invoked after a model instance is created by new operator.
afterValidate() (opens new window) This method is invoked after validation ends.
beforeValidate() (opens new window) This method is invoked before validation starts.
createContent() Creates the content model associated with this element.
defineAttributes() Defines this model's attributes.
getFieldByHandle() Returns the field with a given handle.

# createContent()

Creates the content model associated with this element.

View source (opens new window)

Returns

Craft\ContentModel – The content model associated with this element

Signature

protected Craft\ContentModel createContent ( )

# defineAttributes()

Defines this model's attributes.

BaseModel::defineAttributes()

View source (opens new window)

Returns

array (opens new window)

Signature

protected array defineAttributes ( )

# getFieldByHandle()

Returns the field with a given handle.

View source (opens new window)

Arguments

Returns

Craft\FieldModel, null (opens new window)

Signature

protected Craft\FieldModel, null getFieldByHandle ( $handle )

# Constants

Constant Description
ARCHIVED
DISABLED
ENABLED