ElementCriteriaModel

Type
Class
Namespace
Craft
Inherits
Craft\ElementCriteriaModel » Craft\BaseModel » CModel » CComponent
Implements
ArrayAccess, Countable, IteratorAggregate
Since
1.0

Element criteria model class.

See also http://craftcms.com

View source

Protected Properties

PropertyDescription
$classSuffixstring
$strictAttributesboolean – Whether this model should be strict about only allowing values to be set on defined attributes

$strictAttributes

Type
boolean

Whether this model should be strict about only allowing values to be set on defined attributes

View source

Signature

protected boolean $strictAttributes = false

Public Methods

MethodDescription
__call()Magic __call() method, used for chain-setting attribute values.
__construct()Constructor
__get()PHP getter magic method.
__isset()Treats attributes defined by defineAttributes() as properties.
__set()PHP setter magic method.
__unset()Sets a component property to be null.
addError()Adds a new error to the specified attribute.
addErrors()Adds a list of errors.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
attributeLabels()Returns the attribute labels.
attributeNames()Returns the list of this model's attribute names.
behaviors()Returns a list of behaviors that this model should behave as.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
clearErrors()Removes errors for all attributes or a single attribute.
copy()Returns a copy of this model.
count()Returns the total number of elements matched by this criteria. Required by the Countable interface.
createValidators()Creates validator objects based on the specification in {@link rules}.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
find()Returns all elements that match the criteria.
findElementAtOffset()Returns an element at a specific offset.
first()Returns the first element that matches the criteria.
generateAttributeLabel()Generates a user friendly attribute label.
getAllErrors()Returns all errors in a single, flattened list, devoid of attribute names.
getAttribute()Gets an attribute’s value.
getAttributeConfigs()Returns this model's normalized attribute configs.
getAttributeLabel()Returns the text label for the specified attribute.
getAttributes()Returns an array of attribute values.
getClassHandle()Get the class name, sans namespace and suffix.
getElementType()
getError()Returns the first error of the specified attribute.
getErrors()Returns the errors for all attribute or a single attribute.
getEventHandlers()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.
getIterator()Returns an iterator for traversing over the elements.
getSafeAttributeNames()Returns the attribute names that are safe to be massively assigned.
getScenario()Returns the scenario that this model is used in.
getSupportedFieldHandles()Returns the field handles that didn't conflict with the main attribute names.
getValidatorList()Returns all the validators declared in the model.
getValidators()Returns the validators applicable to the current {@link scenario}.
hasErrors()Returns a value indicating whether there is any validation error.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
ids()Returns all element IDs that match the criteria.
isAttributeRequired()Returns a value indicating whether the attribute is required.
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.
last()Returns the last element that matches the criteria.
nth()Returns an element at a specific offset.
offsetExists()Returns whether an element exists at a given offset. Required by the ArrayAccess interface.
offsetGet()Returns the element at a given offset. Required by the ArrayAccess interface.
offsetSet()Sets the element at a given offset. Required by the ArrayAccess interface.
offsetUnset()Unsets an element at a given offset. Required by the ArrayAccess interface.
onAfterConstruct()This event is raised after the model instance is created by new operator.
onAfterValidate()This event is raised after the validation is performed.
onBeforeValidate()This event is raised before the validation is performed.
onPopulateElements()Fires an 'onPopulateElements' event.
onUnsafeAttribute()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()Raises an event.
rules()Returns this model's validation rules.
setAttribute()Sets an attribute's value.
setAttributes()Sets multiple attribute values at once.
setLanguage()Language => locale
setMatchedElements()Stores the matched elements to avoid redundant DB queries.
setScenario()Sets the scenario for the model.
total()Returns the total elements that match the criteria.
unsetAttributes()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.

__construct()

Constructor

View source

Arguments

Returns

Craft\ElementCriteriaModel

Signature

public Craft\ElementCriteriaModel __construct ( $attributes, Craft\BaseElementType $elementType )

copy()

Returns a copy of this model.

View source

Returns

Craft\BaseModel

Signature

public Craft\BaseModel copy ( )

count()

Returns the total number of elements matched by this criteria. Required by the Countable interface.

View source

Returns

integer

Signature

public integer count ( )

find()

Returns all elements that match the criteria.

View source

Arguments

  • $attributes (array) – Any last-minute parameters that should be added.

Returns

array – The matched elements.

Signature

public array find ( $attributes = null )

findElementAtOffset()

DEPRECATED

Deprecated Deprecated in 2.2. Use {@link nth()} instead.

Returns an element at a specific offset.

View source

Arguments

Returns

Craft\BaseElementModel, null

Signature

public Craft\BaseElementModel, null findElementAtOffset ( $offset )

first()

Returns the first element that matches the criteria.

View source

Arguments

Returns

Craft\BaseElementModel, null

Signature

public Craft\BaseElementModel, null first ( $attributes = null )

getElementType()

Signature

public Craft\BaseElementType getElementType ( )

getIterator()

Returns an iterator for traversing over the elements. Required by the IteratorAggregate interface.

View source

Returns

ArrayIterator

Signature

public ArrayIterator getIterator ( )

getSupportedFieldHandles()

Returns the field handles that didn't conflict with the main attribute names.

View source

Returns

array

Signature

public array getSupportedFieldHandles ( )

ids()

Returns all element IDs that match the criteria.

View source

Arguments

Returns

array

Signature

public array ids ( $attributes = null )

last()

Returns the last element that matches the criteria.

View source

Arguments

Returns

Craft\BaseElementModel, null

Signature

public Craft\BaseElementModel, null last ( $attributes = null )

nth()

Returns an element at a specific offset.

View source

Arguments

Returns

Craft\BaseElementModel, null – The element, if there is one.

Signature

public Craft\BaseElementModel, null nth ( $offset )

offsetExists()

Returns whether an element exists at a given offset. Required by the ArrayAccess interface.

View source

Arguments

  • $offset (mixed)

Returns

boolean

Signature

public boolean offsetExists ( $offset )

offsetGet()

Returns the element at a given offset. Required by the ArrayAccess interface.

View source

Arguments

  • $offset (mixed)

Returns

mixed

Signature

public mixed offsetGet ( $offset )

offsetSet()

Sets the element at a given offset. Required by the ArrayAccess interface.

View source

Arguments

  • $offset (mixed)
  • $item (mixed)

Returns

null

Signature

public null offsetSet ( $offset, $item )

offsetUnset()

Unsets an element at a given offset. Required by the ArrayAccess interface.

View source

Arguments

  • $offset (mixed)

Returns

null

Signature

public null offsetUnset ( $offset )

onPopulateElements()

Fires an 'onPopulateElements' event.

View source

Arguments

Returns

null

Signature

public null onPopulateElements ( Craft\Event $event )

setAttribute()

Sets an attribute's value. In addition, clears the cached values when a new attribute is set.

View source

Arguments

Returns

boolean

Signature

public boolean setAttribute ( $name, $value )

setLanguage()

Language => locale

View source

Arguments

  • $locale

Returns

Craft\ElementCriteriaModel

Signature

public Craft\ElementCriteriaModel setLanguage ( $locale )

setMatchedElements()

Stores the matched elements to avoid redundant DB queries.

View source

Arguments

  • $elements (array) – The matched elements.

Returns

null

Signature

public null setMatchedElements ( $elements )

total()

Returns the total elements that match the criteria.

View source

Arguments

Returns

integer

Signature

public integer total ( $attributes = null )

Protected Methods

MethodDescription
afterConstruct()This method is invoked after a model instance is created by new operator.
afterValidate()This method is invoked after validation ends.
beforeValidate()This method is invoked before validation starts.
defineAttributes()Defines this model's attributes.

defineAttributes()

Defines this model's attributes.

BaseModel::defineAttributes()

View source

Returns

array

Signature

protected array defineAttributes ( )