Skip to content
PHP Ecosystem
Explore

ActiveDataFilter

API reference › yii › data › ActiveDataFilter

ActiveDataFilter allows composing a filtering condition in a format suitable for QueryInterface::where().

See also: DataFilter.

PropertyTypeDescriptionDefined by
$activeValidators read-onlyyii\validators\Validator[]The validators applicable to the current $scenario.yii\base\Model
$attributeMaparrayActual attribute names to be used in searched condition, in format: [filterAttribute => actualAttribute]. Default: [].DataFilter
$attributesarray<string, mixed>Attribute values (name => value).yii\base\Model
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$conditionBuildersarrayMaps filtering condition keywords to build methods. Default: ['AND' => 'buildConjunctionCondition', 'OR' => 'buildConjunctionCondition', 'NOT' => 'buildBlockCondition', '<' => 'buildOperatorCondition', '>' => 'buildOperatorCondition', '<=' => 'buildOperatorCondition', '>=' => 'buildOperatorCondition', '=' => 'buildOperatorCondition', '!=' => 'buildOperatorCondition', 'IN' => 'buildOperatorCondition', 'NOT IN' => 'buildOperatorCondition', 'LIKE' => 'buildOperatorCondition'].ActiveDataFilter
$conditionValidatorsarrayMaps filter condition keywords to validation methods. Default: ['AND' => 'validateConjunctionCondition', 'OR' => 'validateConjunctionCondition', 'NOT' => 'validateBlockCondition', '<' => 'validateOperatorCondition', '>' => 'validateOperatorCondition', '<=' => 'validateOperatorCondition', '>=' => 'validateOperatorCondition', '=' => 'validateOperatorCondition', '!=' => 'validateOperatorCondition', 'IN' => 'validateOperatorCondition', 'NOT IN' => 'validateOperatorCondition', 'LIKE' => 'validateOperatorCondition'].DataFilter
$errorMessagesarray|ClosureError messages in [errorKey => message] format, or a PHP callback returning them.DataFilter
$errors read-onlyarray<string, string[]>Errors for all attributes.yii\base\Model
$filtermixedRaw filter value.DataFilter
$filterAttributeLabelstringLabel for the filter attribute specified via $filterAttributeName. Default: null.DataFilter
$filterAttributeNamestringName of the attribute that handles filter value. Default: 'filter'.DataFilter
$filterControlsarrayKeywords or expressions that could be used in a filter. Default: ['and' => 'AND', 'or' => 'OR', 'not' => 'NOT', 'lt' => '<', 'gt' => '>', 'lte' => '<=', 'gte' => '>=', 'eq' => '=', 'neq' => '!=', 'in' => 'IN', 'nin' => 'NOT IN', 'like' => 'LIKE'].DataFilter
$firstErrors read-onlyarray<string, string>The first errors.yii\base\Model
$iterator read-onlyArrayIterator<string, mixed>An iterator for traversing the items in the list.yii\base\Model
$multiValueOperatorsarrayList of operators keywords, which should accept multiple values. Default: ['IN', 'NOT IN'].DataFilter
$nullValuestringRepresentation of null instead of literal null in case the latter cannot be used. Default: 'NULL'. Available since 2.0.40.DataFilter
$operatorTypesarraySpecifies the list of supported search attribute types per each operator. Default: ['<' => [self::TYPE_INTEGER, self::TYPE_FLOAT, self::TYPE_DATETIME, self::TYPE_DATE, self::TYPE_TIME], '>' => [self::TYPE_INTEGER, self::TYPE_FLOAT, self::TYPE_DATETIME, self::TYPE_DATE, self::TYPE_TIME], '<=' => [self::TYPE_INTEGER, self::TYPE_FLOAT, self::TYPE_DATETIME, self::TYPE_DATE, self::TYPE_TIME], '>=' => [self::TYPE_INTEGER, self::TYPE_FLOAT, self::TYPE_DATETIME, self::TYPE_DATE, self::TYPE_TIME], '=' => '*', '!=' => '*', 'IN' => '*', 'NOT IN' => '*', 'LIKE' => [self::TYPE_STRING]].DataFilter
$queryOperatorMaparrayMap filtering operators to operators used in QueryInterface::where(). Default: [].ActiveDataFilter
$scenariostringThe scenario that this model is in.yii\base\Model
$searchAttributeTypesarray|nullSearch attribute type map.DataFilter
$searchModelyii\base\Model|array|string|callableModel instance or its DI compatible configuration.DataFilter
$validators read-onlyArrayObject<int, yii\validators\Validator>|yii\validators\Validator[]All the validators declared in the model.yii\base\Model
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Model
__get()Returns the value of a component property.DataFilter
__isset()Checks if a property is set, i.e. defined and not null.DataFilter
__set()Sets the value of a component property.DataFilter
__unset()Sets a component property to be null.DataFilter
activeAttributes()Returns the attribute names that are subject to validation in the current scenario.yii\base\Model
addError()Adds a new error to the specified attribute.yii\base\Model
addErrors()Adds a list of errors.yii\base\Model
afterValidate()This method is invoked after validation ends.yii\base\Model
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
attributeHints()Returns the attribute hints.yii\base\Model
attributeLabels()Returns the attribute labels.DataFilter
attributes()Returns the list of attribute names.DataFilter
beforeValidate()This method is invoked before validation starts.yii\base\Model
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
build()Builds actual filter specification form $filter value.DataFilter
canGetProperty()Returns a value indicating whether a property can be read.DataFilter
canSetProperty()Returns a value indicating whether a property can be set.DataFilter
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
clearErrors()Removes errors for all attributes or a single attribute.yii\base\Model
createValidators()Creates validator objects based on the validation rules specified in rules().yii\base\Model
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
extraFields()Returns the list of fields that can be expanded further and returned by toArray().yii\base\ArrayableTrait
fields()Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.yii\base\Model
formName()Returns the form name that this model class should use.DataFilter
generateAttributeLabel()Generates a user friendly attribute label based on the give attribute name.yii\base\Model
getActiveValidators()Returns the validators applicable to the current $scenario.yii\base\Model
getAttributeHint()Returns the text hint for the specified attribute.yii\base\Model
getAttributeLabel()Returns the text label for the specified attribute.yii\base\Model
getAttributes()Returns attribute values.yii\base\Model
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getErrorMessages()DataFilter
getErrors()Returns the errors for all attributes or a single attribute.yii\base\Model
getErrorSummary()Returns the errors for all attributes as a one-dimensional array.yii\base\Model
getFilter()DataFilter
getFirstError()Returns the first error of the specified attribute.yii\base\Model
getFirstErrors()Returns the first error of every attribute in the model.yii\base\Model
getIterator()Returns an iterator for traversing the attributes in the model.yii\base\Model
getScenario()Returns the scenario that this model is used in.yii\base\Model
getSearchAttributeTypes()DataFilter
getSearchModel()DataFilter
getValidators()Returns all the validators declared in rules().yii\base\Model
hasErrors()Returns a value indicating whether there is any validation error.yii\base\Model
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes the object.yii\base\BaseObject
instance() staticReturns static class instance, which can be used to obtain meta information.yii\base\StaticInstanceTrait
isAttributeActive()Returns a value indicating whether the attribute is active in the current scenario.yii\base\Model
isAttributeRequired()Returns a value indicating whether the attribute is required.yii\base\Model
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.yii\base\Model
load()Populates the model with input data.yii\base\Model
loadMultiple() staticPopulates a set of models with the data from end user.yii\base\Model
normalize()Normalizes filter value, replacing raw keys according to $filterControls and $attributeMap.DataFilter
off()Detaches an existing event handler from this component.yii\base\Component
offsetExists()Returns whether there is an element at the specified offset.yii\base\Model
offsetGet()Returns the element at the specified offset.yii\base\Model
offsetSet()Sets the element at the specified offset.yii\base\Model
offsetUnset()Sets the element value at the specified offset to null.yii\base\Model
on()Attaches an event handler to an event.yii\base\Component
onUnsafeAttribute()This method is invoked when an unsafe attribute is being massively assigned.yii\base\Model
rules()Returns the validation rules for attributes.DataFilter
safeAttributes()Returns the attribute names that are safe to be massively assigned in the current scenario.yii\base\Model
scenarios()Returns a list of scenarios and the corresponding active attributes.yii\base\Model
setAttributes()Sets the attribute values in a massive way.yii\base\Model
setErrorMessages()Sets the list of error messages responding to invalid filter structure, in format: [errorKey => message].DataFilter
setFilter()DataFilter
setScenario()Sets the scenario for the model.yii\base\Model
setSearchAttributeTypes()DataFilter
setSearchModel()DataFilter
toArray()Converts the model into an array.yii\base\ArrayableTrait
trigger()Triggers an event.yii\base\Component
validate()Performs the data validation.yii\base\Model
validateFilter()Validates filter attribute value to match filer condition specification.DataFilter
validateMultiple() staticValidates multiple models.yii\base\Model
buildAttributeCondition() protectedBuilds search condition for a particular attribute.ActiveDataFilter
buildBlockCondition() protectedBuilds block condition, which consists of a single condition.ActiveDataFilter
buildCondition() protectedActiveDataFilter
buildConjunctionCondition() protectedBuilds conjunction condition, which consists of multiple independent ones.ActiveDataFilter
buildInternal() protectedPerforms actual filter build.ActiveDataFilter
buildOperatorCondition() protectedBuilds an operator condition.ActiveDataFilter
defaultErrorMessages() protectedReturns default values for $errorMessages.DataFilter
detectSearchAttributeType() protectedDetect attribute type from given validator.DataFilter
detectSearchAttributeTypes() protectedComposes default value for $searchAttributeTypes from the $searchModel validation rules.DataFilter
extractFieldsFor() protectedExtract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: “item.id” The previous example would extract “id”.yii\base\ArrayableTrait
extractRootFields() protectedExtracts the root field names from nested fields.yii\base\ArrayableTrait
filterAttributeValue() protectedValidates attribute value in the scope of $searchModel, applying attribute value filters if any.DataFilter
parseErrorMessage() protectedParses content of the message from $errorMessages, specified by message key.DataFilter
resolveFields() protectedDetermines which fields can be returned by toArray().yii\base\ArrayableTrait
validateAttributeCondition() protectedValidates search condition for a particular attribute.DataFilter
validateAttributeValue() protectedValidates attribute value in the scope of Model.DataFilter
validateBlockCondition() protectedValidates block condition that consists of a single condition.DataFilter
validateCondition() protectedValidates filter condition.DataFilter
validateConjunctionCondition() protectedValidates conjunction condition that consists of multiple independent ones.DataFilter
validateOperatorCondition() protectedValidates operator condition.DataFilter
EventTypeDescriptionDefined by
EVENT_BEFORE_VALIDATEyii\base\ModelEventAn event raised at the beginning of validate(). Event name: 'beforeValidate'.yii\base\Model
EVENT_AFTER_VALIDATEyii\base\EventAn event raised at the end of validate() Event name: 'afterValidate'.yii\base\Model
ConstantValueDescriptionDefined by
TYPE_INTEGER'integer'DataFilter
TYPE_FLOAT'float'DataFilter
TYPE_BOOLEAN'boolean'DataFilter
TYPE_STRING'string'DataFilter
TYPE_ARRAY'array'DataFilter
TYPE_DATETIME'datetime'DataFilter
TYPE_DATE'date'DataFilter
TYPE_TIME'time'DataFilter
SCENARIO_DEFAULT'default'The name of the default scenario.yii\base\Model
public array $conditionBuilders = ['AND' => 'buildConjunctionCondition', 'OR' => 'buildConjunctionCondition', 'NOT' => 'buildBlockCondition', '<' => 'buildOperatorCondition', '>' => 'buildOperatorCondition', '<=' => 'buildOperatorCondition', '>=' => 'buildOperatorCondition', '=' => 'buildOperatorCondition', '!=' => 'buildOperatorCondition', 'IN' => 'buildOperatorCondition', 'NOT IN' => 'buildOperatorCondition', 'LIKE' => 'buildOperatorCondition']

Maps filtering condition keywords to build methods.

These methods are used by buildCondition() to build the actual filtering conditions. Particular condition builder can be specified using a PHP callback. For example:

[
'XOR' => function (string $operator, mixed $condition) {
//return array;
},
'LIKE' => function (string $operator, mixed $condition, string $attribute) {
//return array;
},
]
public array $queryOperatorMap = []

Map filtering operators to operators used in QueryInterface::where().

The format is: [filterOperator => queryOperator]. If particular operator keyword does not appear in the map, it will be used as is.

Usually the map can be left empty as filter operator names are consistent with the ones used in QueryInterface::where(). However, you may want to adjust it in some special cases. For example, when using PostgreSQL you may want to setup the following map:

[
'LIKE' => 'ILIKE'
]
protected function buildAttributeCondition(string $attribute, mixed $condition): array

Builds search condition for a particular attribute.

Parameters

ParameterTypeDescription
$attributestringSearch attribute name.
$conditionmixedSearch condition.

Returns

array: Actual condition.

protected function buildBlockCondition(string $operator, mixed $condition): array

Builds block condition, which consists of a single condition.

It covers such operators as not.

Parameters

ParameterTypeDescription
$operatorstringOperator keyword.
$conditionmixedRaw condition.

Returns

array: Actual condition.

protected function buildCondition(array $condition): array

Parameters

ParameterTypeDescription
$conditionarray

Returns

array: Built condition.

protected function buildConjunctionCondition(string $operator, mixed $condition): array

Builds conjunction condition, which consists of multiple independent ones.

It covers such operators as and and or.

Parameters

ParameterTypeDescription
$operatorstringOperator keyword.
$conditionmixedRaw condition.

Returns

array: Actual condition.

protected function buildInternal(): mixed

Performs actual filter build.

By default this method returns result of normalize(). The child class may override this method providing more specific implementation.

Returns

mixed: Built actual filter value.

protected function buildOperatorCondition(string $operator, mixed $condition, string $attribute): array

Builds an operator condition.

Parameters

ParameterTypeDescription
$operatorstringOperator keyword.
$conditionmixedAttribute condition.
$attributestringAttribute name.

Returns

array: Actual condition.