HumHub Documentation (unofficial)

ActiveDataFilter extends DataFilter
in package

ActiveDataFilter allows composing a filtering condition in a format suitable for [[\yii\db\QueryInterface::where()]].

Tags
see
DataFilter
author

Paul Klimov klimov.paul@gmail.com

since
2.0.13

Table of Contents

Constants

EVENT_AFTER_VALIDATE  = 'afterValidate'
EVENT_BEFORE_VALIDATE  = 'beforeValidate'
SCENARIO_DEFAULT  = 'default'
The name of the default scenario.
TYPE_ARRAY  = 'array'
TYPE_BOOLEAN  = 'boolean'
TYPE_DATE  = 'date'
TYPE_DATETIME  = 'datetime'
TYPE_FLOAT  = 'float'
TYPE_INTEGER  = 'integer'
TYPE_STRING  = 'string'
TYPE_TIME  = 'time'

Properties

$activeValidators  : array<string|int, Validator>
$attributeMap  : array<string|int, mixed>
$attributes  : array<string|int, mixed>
$behaviors  : array<string|int, Behavior>
$conditionBuilders  : array<string|int, mixed>
$conditionValidators  : array<string|int, mixed>
$errorMessages  : array<string|int, mixed>
$errors  : array<string|int, mixed>
$filter  : mixed
$filterAttributeLabel  : string
$filterAttributeName  : string
$filterControls  : array<string|int, mixed>
$firstErrors  : array<string|int, mixed>
$multiValueOperators  : array<string|int, mixed>
$nullValue  : string
$operatorTypes  : array<string|int, mixed>
$queryOperatorMap  : array<string|int, mixed>
$scenario  : string
$searchAttributeTypes  : array<string|int, mixed>
$searchModel  : Model
$validators  : ArrayObject|array<string|int, Validator>
$_behaviors  : array<string|int, Behavior>|null
$_errorMessages  : array<string|int, mixed>|Closure
$_errors  : array<string|int, mixed>
$_events  : array<string|int, mixed>
$_eventWildcards  : array<string|int, mixed>
$_filter  : mixed
$_instances  : array<string|int, static>
$_scenario  : string
$_searchAttributeTypes  : array<string|int, mixed>
$_searchModel  : Model|array<string|int, mixed>|string|callable
$_validators  : ArrayObject

Methods

__call()  : mixed
Calls the named method which is not a class method.
__clone()  : mixed
This method is called after the object is created by cloning an existing one.
__construct()  : mixed
Constructor.
__get()  : mixed
Returns the value of a component property.
__isset()  : bool
Checks if a property is set, i.e. defined and not null.
__set()  : mixed
Sets the value of a component property.
__unset()  : mixed
Sets a component property to be null.
activeAttributes()  : array<string|int, string>
Returns the attribute names that are subject to validation in the current scenario.
addError()  : mixed
Adds a new error to the specified attribute.
addErrors()  : mixed
Adds a list of errors.
afterValidate()  : mixed
This method is invoked after validation ends.
attachBehavior()  : Behavior
Attaches a behavior to this component.
attachBehaviors()  : mixed
Attaches a list of behaviors to the component.
attributeHints()  : array<string|int, mixed>
Returns the attribute hints.
attributeLabels()  : array<string|int, mixed>
Returns the attribute labels.
attributes()  : array<string|int, string>
Returns the list of attribute names.
beforeValidate()  : bool
This method is invoked before validation starts.
behaviors()  : array<string|int, mixed>
Returns a list of behaviors that this component should behave as.
build()  : mixed|false
Builds actual filter specification form [[filter]] value.
canGetProperty()  : bool
Returns a value indicating whether a property can be read.
canSetProperty()  : bool
Returns a value indicating whether a property can be set.
className()  : string
Returns the fully qualified name of this class.
clearErrors()  : mixed
Removes errors for all attributes or a single attribute.
createValidators()  : ArrayObject
Creates validator objects based on the validation rules specified in [[rules()]].
detachBehavior()  : Behavior|null
Detaches a behavior from the component.
detachBehaviors()  : mixed
Detaches all behaviors from the component.
ensureBehaviors()  : mixed
Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
extraFields()  : array<string|int, mixed>
Returns the list of fields that can be expanded further and returned by [[toArray()]].
fields()  : array<string|int, mixed>
Returns the list of fields that should be returned by default by [[toArray()]] when no specific fields are specified.
formName()  : string
Returns the form name that this model class should use.
generateAttributeLabel()  : string
Generates a user friendly attribute label based on the give attribute name.
getActiveValidators()  : array<string|int, Validator>
Returns the validators applicable to the current [[scenario]].
getAttributeHint()  : string
Returns the text hint for the specified attribute.
getAttributeLabel()  : string
Returns the text label for the specified attribute.
getAttributes()  : array<string|int, mixed>
Returns attribute values.
getBehavior()  : Behavior|null
Returns the named behavior object.
getBehaviors()  : array<string|int, Behavior>
Returns all behaviors attached to this component.
getErrorMessages()  : array<string|int, mixed>
getErrors()  : array<string|int, mixed>
Returns the errors for all attributes or a single attribute.
getErrorSummary()  : array<string|int, mixed>
Returns the errors for all attributes as a one-dimensional array.
getFilter()  : mixed
getFirstError()  : string|null
Returns the first error of the specified attribute.
getFirstErrors()  : array<string|int, mixed>
Returns the first error of every attribute in the model.
getIterator()  : ArrayIterator
Returns an iterator for traversing the attributes in the model.
getScenario()  : string
Returns the scenario that this model is used in.
getSearchAttributeTypes()  : array<string|int, mixed>
getSearchModel()  : Model
getValidators()  : ArrayObject|array<string|int, Validator>
Returns all the validators declared in [[rules()]].
hasErrors()  : bool
Returns a value indicating whether there is any validation error.
hasEventHandlers()  : bool
Returns a value indicating whether there is any handler attached to the named event.
hasMethod()  : bool
Returns a value indicating whether a method is defined.
hasProperty()  : bool
Returns a value indicating whether a property is defined for this component.
init()  : mixed
Initializes the object.
instance()  : static
Returns static class instance, which can be used to obtain meta information.
isAttributeActive()  : bool
Returns a value indicating whether the attribute is active in the current scenario.
isAttributeRequired()  : bool
Returns a value indicating whether the attribute is required.
isAttributeSafe()  : bool
Returns a value indicating whether the attribute is safe for massive assignments.
load()  : bool
Populates the model with input data.
loadMultiple()  : bool
Populates a set of models with the data from end user.
normalize()  : array<string|int, mixed>|bool
Normalizes filter value, replacing raw keys according to [[filterControls]] and [[attributeMap]].
off()  : bool
Detaches an existing event handler from this component.
offsetExists()  : bool
Returns whether there is an element at the specified offset.
offsetGet()  : mixed
Returns the element at the specified offset.
offsetSet()  : mixed
Sets the element at the specified offset.
offsetUnset()  : mixed
Sets the element value at the specified offset to null.
on()  : mixed
Attaches an event handler to an event.
onUnsafeAttribute()  : mixed
This method is invoked when an unsafe attribute is being massively assigned.
rules()  : array<string|int, mixed>
Returns the validation rules for attributes.
safeAttributes()  : array<string|int, string>
Returns the attribute names that are safe to be massively assigned in the current scenario.
scenarios()  : array<string|int, mixed>
Returns a list of scenarios and the corresponding active attributes.
setAttributes()  : mixed
Sets the attribute values in a massive way.
setErrorMessages()  : mixed
Sets the list of error messages responding to invalid filter structure, in format: `[errorKey => message]`.
setFilter()  : mixed
setScenario()  : mixed
Sets the scenario for the model.
setSearchAttributeTypes()  : mixed
setSearchModel()  : mixed
toArray()  : array<string|int, mixed>
Converts the model into an array.
trigger()  : mixed
Triggers an event.
validate()  : bool
Performs the data validation.
validateFilter()  : mixed
Validates filter attribute value to match filer condition specification.
validateMultiple()  : bool
Validates multiple models.
buildAttributeCondition()  : array<string|int, mixed>
Builds search condition for a particular attribute.
buildBlockCondition()  : array<string|int, mixed>
Builds block condition, which consists of a single condition.
buildCondition()  : array<string|int, mixed>
buildConjunctionCondition()  : array<string|int, mixed>
Builds conjunction condition, which consists of multiple independent ones.
buildInternal()  : mixed
Performs actual filter build.
buildOperatorCondition()  : array<string|int, mixed>
Builds an operator condition.
defaultErrorMessages()  : array<string|int, mixed>
Returns default values for [[errorMessages]].
detectSearchAttributeType()  : string|null
Detect attribute type from given validator.
detectSearchAttributeTypes()  : array<string|int, mixed>
Composes default value for [[searchAttributeTypes]] from the [[searchModel]] validation rules.
extractFieldsFor()  : array<string|int, mixed>
Extract 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".
extractRootFields()  : array<string|int, mixed>
Extracts the root field names from nested fields.
filterAttributeValue()  : mixed
Validates attribute value in the scope of [[searchModel]], applying attribute value filters if any.
parseErrorMessage()  : string
Parses content of the message from [[errorMessages]], specified by message key.
resolveFields()  : array<string|int, mixed>
Determines which fields can be returned by [[toArray()]].
validateAttributeCondition()  : mixed
Validates search condition for a particular attribute.
validateAttributeValue()  : mixed
Validates attribute value in the scope of [[model]].
validateBlockCondition()  : mixed
Validates block condition that consists of a single condition.
validateCondition()  : mixed
Validates filter condition.
validateConjunctionCondition()  : mixed
Validates conjunction condition that consists of multiple independent ones.
validateOperatorCondition()  : mixed
Validates operator condition.
attachBehaviorInternal()  : Behavior
Attaches a behavior to this component.
normalizeComplexFilter()  : array<string|int, mixed>
Normalizes complex filter recursively.

Constants

EVENT_AFTER_VALIDATE

public mixed EVENT_AFTER_VALIDATE = 'afterValidate'
Tags
event

Event an event raised at the end of [[validate()]]

EVENT_BEFORE_VALIDATE

public mixed EVENT_BEFORE_VALIDATE = 'beforeValidate'
Tags
event

ModelEvent an event raised at the beginning of [[validate()]]. You may set [[ModelEvent::isValid]] to be false to stop the validation.

SCENARIO_DEFAULT

The name of the default scenario.

public mixed SCENARIO_DEFAULT = 'default'

TYPE_BOOLEAN

public mixed TYPE_BOOLEAN = 'boolean'

TYPE_DATETIME

public mixed TYPE_DATETIME = 'datetime'

TYPE_INTEGER

public mixed TYPE_INTEGER = 'integer'

TYPE_STRING

public mixed TYPE_STRING = 'string'

Properties

$activeValidators read-only

public array<string|int, Validator> $activeValidators

The validators applicable to the current [[scenario]].

$attributeMap

public array<string|int, mixed> $attributeMap = []

actual attribute names to be used in searched condition, in format: [filterAttribute => actualAttribute]. For example, in case of using table joins in the search query, attribute map may look like the following:

[
    'authorName' => '{{author}}.[[name]]'
]

Attribute map will be applied to filter condition in [[normalize()]] method.

$attributes

public array<string|int, mixed> $attributes

Attribute values (name => value).

$behaviors read-only

public array<string|int, Behavior> $behaviors

List of behaviors attached to this component.

$conditionBuilders

public array<string|int, mixed> $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;
    },
]

$conditionValidators

public array<string|int, mixed> $conditionValidators = ['AND' => 'validateConjunctionCondition', 'OR' => 'validateConjunctionCondition', 'NOT' => 'validateBlockCondition', '<' => 'validateOperatorCondition', '>' => 'validateOperatorCondition', '<=' => 'validateOperatorCondition', '>=' => 'validateOperatorCondition', '=' => 'validateOperatorCondition', '!=' => 'validateOperatorCondition', 'IN' => 'validateOperatorCondition', 'NOT IN' => 'validateOperatorCondition', 'LIKE' => 'validateOperatorCondition']

maps filter condition keywords to validation methods. These methods are used by [[validateCondition()]] to validate raw filter conditions.

$errorMessages

public array<string|int, mixed> $errorMessages

Error messages in format [errorKey => message]. Note that the type of this property differs in getter and setter. See [[getErrorMessages()]] and [[setErrorMessages()]] for details.

$errors read-only

public array<string|int, mixed> $errors

Errors for all attributes or the specified attribute. Empty array is returned if no error. See [[getErrors()]] for detailed description. Note that when returning errors for all attributes, the result is a two-dimensional array, like the following: php [ 'username' => [ 'Username is required.', 'Username must contain only word characters.', ], 'email' => [ 'Email address is invalid.', ] ] .

$filterAttributeLabel

public string $filterAttributeLabel

label for the filter attribute specified via [[filterAttributeName]]. It will be used during error messages composition.

$filterAttributeName

public string $filterAttributeName = 'filter'

name of the attribute that handles filter value. The name is used to load data via [[load()]] method.

$filterControls

public array<string|int, mixed> $filterControls = ['and' => 'AND', 'or' => 'OR', 'not' => 'NOT', 'lt' => '<', 'gt' => '>', 'lte' => '<=', 'gte' => '>=', 'eq' => '=', 'neq' => '!=', 'in' => 'IN', 'nin' => 'NOT IN', 'like' => 'LIKE']

keywords or expressions that could be used in a filter. Array keys are the expressions used in raw filter value obtained from user request. Array values are internal build keys used in this class methods.

Any unspecified keyword will not be recognized as a filter control and will be treated as an attribute name. Thus you should avoid conflicts between control keywords and attribute names. For example: in case you have control keyword 'like' and an attribute named 'like', specifying condition for such attribute will be impossible.

You may specify several keywords for the same filter build key, creating multiple aliases. For example:

[
    'eq' => '=',
    '=' => '=',
    '==' => '=',
    '===' => '=',
    // ...
]

Note: while specifying filter controls take actual data exchange format, which your API uses, in mind. Make sure each specified control keyword is valid for the format. For example, in XML tag name can start only with a letter character, thus controls like >, '=' or $gt will break the XML schema.

$firstErrors read-only

public array<string|int, mixed> $firstErrors

The first errors. The array keys are the attribute names, and the array values are the corresponding error messages. An empty array will be returned if there is no error.

$multiValueOperators

public array<string|int, mixed> $multiValueOperators = ['IN', 'NOT IN']

list of operators keywords, which should accept multiple values.

$nullValue

public string $nullValue = 'NULL'

representation of null instead of literal null in case the latter cannot be used.

Tags
since
2.0.40

$operatorTypes

public array<string|int, mixed> $operatorTypes = ['<' => [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]]

specifies the list of supported search attribute types per each operator. This field should be in format: 'operatorKeyword' => ['type1', 'type2' ...]. Supported types list can be specified as *, which indicates that operator supports all types available. Any unspecified keyword will not be considered as a valid operator.

$queryOperatorMap

public array<string|int, mixed> $queryOperatorMap = []

map filtering operators to operators used in [[\yii\db\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 [[\yii\db\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'
]

$scenario

public string $scenario

The scenario that this model is in. Defaults to [[SCENARIO_DEFAULT]].

$searchAttributeTypes

public array<string|int, mixed> $searchAttributeTypes

Search attribute type map. Note that the type of this property differs in getter and setter. See [[getSearchAttributeTypes()]] and [[setSearchAttributeTypes()]] for details.

$searchModel

public Model $searchModel

Model instance. Note that the type of this property differs in getter and setter. See [[getSearchModel()]] and [[setSearchModel()]] for details.

$validators read-only

public ArrayObject|array<string|int, Validator> $validators

All the validators declared in the model.

$_behaviors

private array<string|int, Behavior>|null $_behaviors

the attached behaviors (behavior name => behavior). This is null when not initialized.

$_errorMessages

private array<string|int, mixed>|Closure $_errorMessages

list of error messages responding to invalid filter structure, in format: [errorKey => message].

$_errors

private array<string|int, mixed> $_errors

validation errors (attribute name => array of errors)

$_events

private array<string|int, mixed> $_events = []

the attached event handlers (event name => handlers)

$_eventWildcards

private array<string|int, mixed> $_eventWildcards = []

the event handlers attached for wildcard patterns (event name wildcard => handlers)

Tags
since
2.0.14

$_filter

private mixed $_filter

raw filter specification.

$_instances

private static array<string|int, static> $_instances = []

static instances in format: [className => object]

$_scenario

private string $_scenario = self::SCENARIO_DEFAULT

current scenario

$_searchAttributeTypes

private array<string|int, mixed> $_searchAttributeTypes

list of search attribute types in format: attributeName => type

$_searchModel

private Model|array<string|int, mixed>|string|callable $_searchModel

model to be used for filter attributes validation.

$_validators

private ArrayObject $_validators

list of validators

Methods

__call()

Calls the named method which is not a class method.

public __call(string $name, array<string|int, mixed> $params) : mixed

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

Parameters
$name : string

the method name

$params : array<string|int, mixed>

method parameters

Tags
throws
UnknownMethodException

when calling unknown method

Return values
mixed

the method return value

__clone()

This method is called after the object is created by cloning an existing one.

public __clone() : mixed

__construct()

Constructor.

public __construct([array<string|int, mixed> $config = [] ]) : mixed

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call [[init()]].

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
Parameters
$config : array<string|int, mixed> = []

name-value pairs that will be used to initialize the object properties

__get()

Returns the value of a component property.

public __get(mixed $name) : mixed
Parameters
$name : mixed

the property name

Return values
mixed

the property value or the value of a behavior's property

__isset()

Checks if a property is set, i.e. defined and not null.

public __isset(mixed $name) : bool
Parameters
$name : mixed

the property name or the event name

Return values
bool

whether the named property is set

__set()

Sets the value of a component property.

public __set(mixed $name, mixed $value) : mixed
Parameters
$name : mixed

the property name or the event name

$value : mixed

the property value

__unset()

Sets a component property to be null.

public __unset(mixed $name) : mixed
Parameters
$name : mixed

the property name

activeAttributes()

Returns the attribute names that are subject to validation in the current scenario.

public activeAttributes() : array<string|int, string>
Return values
array<string|int, string>

safe attribute names

addError()

Adds a new error to the specified attribute.

public addError(string $attribute[, string $error = '' ]) : mixed
Parameters
$attribute : string

attribute name

$error : string = ''

new error message

addErrors()

Adds a list of errors.

public addErrors(array<string|int, mixed> $items) : mixed
Parameters
$items : array<string|int, mixed>

a list of errors. The array keys must be attribute names. The array values should be error messages. If an attribute has multiple errors, these errors must be given in terms of an array. You may use the result of [[getErrors()]] as the value for this parameter.

Tags
since
2.0.2

afterValidate()

This method is invoked after validation ends.

public afterValidate() : mixed

The default implementation raises an afterValidate event. You may override this method to do postprocessing after validation. Make sure the parent implementation is invoked so that the event can be raised.

attachBehavior()

Attaches a behavior to this component.

public attachBehavior(string $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.

Parameters
$name : string

the name of the behavior.

$behavior : string|array<string|int, mixed>|Behavior

the behavior configuration. This can be one of the following:

  • a [[Behavior]] object
  • a string specifying the behavior class
  • an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Tags
see
detachBehavior()
Return values
Behavior

the behavior object

attachBehaviors()

Attaches a list of behaviors to the component.

public attachBehaviors(array<string|int, mixed> $behaviors) : mixed

Each behavior is indexed by its name and should be a [[Behavior]] object, a string specifying the behavior class, or an configuration array for creating the behavior.

Parameters
$behaviors : array<string|int, mixed>

list of behaviors to be attached to the component

Tags
see
attachBehavior()

attributeHints()

Returns the attribute hints.

public attributeHints() : array<string|int, mixed>

Attribute hints are mainly used for display purpose. For example, given an attribute isPublic, we can declare a hint Whether the post should be visible for not logged in users, which provides user-friendly description of the attribute meaning and can be displayed to end users.

Unlike label hint will not be generated, if its explicit declaration is omitted.

Note, in order to inherit hints defined in the parent class, a child class needs to merge the parent hints with child hints using functions such as array_merge().

Tags
since
2.0.4
Return values
array<string|int, mixed>

attribute hints (name => hint)

attributeLabels()

Returns the attribute labels.

public attributeLabels() : array<string|int, mixed>
Return values
array<string|int, mixed>

attribute labels (name => label)

attributes()

Returns the list of attribute names.

public attributes() : array<string|int, string>
Return values
array<string|int, string>

list of attribute names.

beforeValidate()

This method is invoked before validation starts.

public beforeValidate() : bool

The default implementation raises a beforeValidate event. You may override this method to do preliminary checks before validation. Make sure the parent implementation is invoked so that the event can be raised.

Return values
bool

whether the validation should be executed. Defaults to true. If false is returned, the validation will stop and the model is considered invalid.

behaviors()

Returns a list of behaviors that this component should behave as.

public behaviors() : array<string|int, mixed>

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from [[Behavior]]. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using [[getBehavior()]] or be detached using [[detachBehavior()]]. Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

Return values
array<string|int, mixed>

the behavior configurations.

build()

Builds actual filter specification form [[filter]] value.

public build([bool $runValidation = true ]) : mixed|false
Parameters
$runValidation : bool = true

whether to perform validation (calling [[validate()]]) before building the filter. Defaults to true. If the validation fails, no filter will be built and this method will return false.

Return values
mixed|false

built actual filter value, or false if validation fails.

canGetProperty()

Returns a value indicating whether a property can be read.

public canGetProperty(mixed $name[, mixed $checkVars = true ][, mixed $checkBehaviors = true ]) : bool
Parameters
$name : mixed

the property name

$checkVars : mixed = true

whether to treat member variables as properties

$checkBehaviors : mixed = true

whether to treat behaviors' properties as properties of this component

Return values
bool

whether the property can be read

canSetProperty()

Returns a value indicating whether a property can be set.

public canSetProperty(mixed $name[, mixed $checkVars = true ][, mixed $checkBehaviors = true ]) : bool
Parameters
$name : mixed

the property name

$checkVars : mixed = true

whether to treat member variables as properties

$checkBehaviors : mixed = true

whether to treat behaviors' properties as properties of this component

Return values
bool

whether the property can be written

className()

Returns the fully qualified name of this class.

public static className() : string
Tags
deprecated

since 2.0.14. On PHP >=5.5, use ::class instead.

Return values
string

the fully qualified name of this class.

clearErrors()

Removes errors for all attributes or a single attribute.

public clearErrors([string|null $attribute = null ]) : mixed
Parameters
$attribute : string|null = null

attribute name. Use null to remove errors for all attributes.

createValidators()

Creates validator objects based on the validation rules specified in [[rules()]].

public createValidators() : ArrayObject

Unlike [[getValidators()]], each time this method is called, a new list of validators will be returned.

Tags
throws
InvalidConfigException

if any validation rule configuration is invalid

Return values
ArrayObject

validators

detachBehavior()

Detaches a behavior from the component.

public detachBehavior(string $name) : Behavior|null

The behavior's [[Behavior::detach()]] method will be invoked.

Parameters
$name : string

the behavior's name.

Return values
Behavior|null

the detached behavior. Null if the behavior does not exist.

detachBehaviors()

Detaches all behaviors from the component.

public detachBehaviors() : mixed

ensureBehaviors()

Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.

public ensureBehaviors() : mixed

extraFields()

Returns the list of fields that can be expanded further and returned by [[toArray()]].

public extraFields() : array<string|int, mixed>

This method is similar to [[fields()]] except that the list of fields returned by this method are not returned by default by [[toArray()]]. Only when field names to be expanded are explicitly specified when calling [[toArray()]], will their values be exported.

The default implementation returns an empty array.

You may override this method to return a list of expandable fields based on some context information (e.g. the current application user).

Tags
see
toArray()
see
fields()
Return values
array<string|int, mixed>

the list of expandable field names or field definitions. Please refer to [[fields()]] on the format of the return value.

fields()

Returns the list of fields that should be returned by default by [[toArray()]] when no specific fields are specified.

public fields() : array<string|int, mixed>

A field is a named element in the returned array by [[toArray()]].

This method should return an array of field names or field definitions. If the former, the field name will be treated as an object property name whose value will be used as the field value. If the latter, the array key should be the field name while the array value should be the corresponding field definition which can be either an object property name or a PHP callable returning the corresponding field value. The signature of the callable should be:

function ($model, $field) {
    // return field value
}

For example, the following code declares four fields:

  • email: the field name is the same as the property name email;
  • firstName and lastName: the field names are firstName and lastName, and their values are obtained from the first_name and last_name properties;
  • fullName: the field name is fullName. Its value is obtained by concatenating first_name and last_name.
return [
    'email',
    'firstName' => 'first_name',
    'lastName' => 'last_name',
    'fullName' => function ($model) {
        return $model->first_name . ' ' . $model->last_name;
    },
];

In this method, you may also want to return different lists of fields based on some context information. For example, depending on [[scenario]] or the privilege of the current application user, you may return different sets of visible fields or filter out some fields.

The default implementation of this method returns [[attributes()]] indexed by the same attribute names.

Tags
see
toArray()
Return values
array<string|int, mixed>

the list of field names or field definitions.

formName()

Returns the form name that this model class should use.

public formName() : string
Return values
string

the form name of this model class.

generateAttributeLabel()

Generates a user friendly attribute label based on the give attribute name.

public generateAttributeLabel(string $name) : string

This is done by replacing underscores, dashes and dots with blanks and changing the first letter of each word to upper case. For example, 'department_name' or 'DepartmentName' will generate 'Department Name'.

Parameters
$name : string

the column name

Return values
string

the attribute label

getActiveValidators()

Returns the validators applicable to the current [[scenario]].

public getActiveValidators([string|null $attribute = null ]) : array<string|int, Validator>
Parameters
$attribute : string|null = null

the name of the attribute whose applicable validators should be returned. If this is null, the validators for ALL attributes in the model will be returned.

Return values
array<string|int, Validator>

the validators applicable to the current [[scenario]].

getAttributeHint()

Returns the text hint for the specified attribute.

public getAttributeHint(string $attribute) : string
Parameters
$attribute : string

the attribute name

Tags
see
attributeHints()
since
2.0.4
Return values
string

the attribute hint

getAttributeLabel()

Returns the text label for the specified attribute.

public getAttributeLabel(string $attribute) : string
Parameters
$attribute : string

the attribute name

Tags
see
generateAttributeLabel()
see
attributeLabels()
Return values
string

the attribute label

getAttributes()

Returns attribute values.

public getAttributes([array<string|int, mixed>|null $names = null ][, array<string|int, mixed> $except = [] ]) : array<string|int, mixed>
Parameters
$names : array<string|int, mixed>|null = null

list of attributes whose value needs to be returned. Defaults to null, meaning all attributes listed in [[attributes()]] will be returned. If it is an array, only the attributes in the array will be returned.

$except : array<string|int, mixed> = []

list of attributes whose value should NOT be returned.

Return values
array<string|int, mixed>

attribute values (name => value).

getBehavior()

Returns the named behavior object.

public getBehavior(string $name) : Behavior|null
Parameters
$name : string

the behavior name

Return values
Behavior|null

the behavior object, or null if the behavior does not exist

getBehaviors()

Returns all behaviors attached to this component.

public getBehaviors() : array<string|int, Behavior>
Return values
array<string|int, Behavior>

list of behaviors attached to this component

getErrorMessages()

public getErrorMessages() : array<string|int, mixed>
Return values
array<string|int, mixed>

error messages in format [errorKey => message].

getErrors()

Returns the errors for all attributes or a single attribute.

public getErrors([string|null $attribute = null ]) : array<string|int, mixed>
Parameters
$attribute : string|null = null

attribute name. Use null to retrieve errors for all attributes.

Tags
see
getFirstErrors()
see
getFirstError()
Return values
array<string|int, mixed>

errors for all attributes or the specified attribute. Empty array is returned if no error. See [[getErrors()]] for detailed description. Note that when returning errors for all attributes, the result is a two-dimensional array, like the following:

[
    'username' => [
        'Username is required.',
        'Username must contain only word characters.',
    ],
    'email' => [
        'Email address is invalid.',
    ]
]

getErrorSummary()

Returns the errors for all attributes as a one-dimensional array.

public getErrorSummary(bool $showAllErrors) : array<string|int, mixed>
Parameters
$showAllErrors : bool

boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown.

Tags
see
getErrors()
see
getFirstErrors()
since
2.0.14
Return values
array<string|int, mixed>

errors for all attributes as a one-dimensional array. Empty array is returned if no error.

getFilter()

public getFilter() : mixed
Return values
mixed

raw filter value.

getFirstError()

Returns the first error of the specified attribute.

public getFirstError(string $attribute) : string|null
Parameters
$attribute : string

attribute name.

Tags
see
getErrors()
see
getFirstErrors()
Return values
string|null

the error message. Null is returned if no error.

getFirstErrors()

Returns the first error of every attribute in the model.

public getFirstErrors() : array<string|int, mixed>
Tags
see
getErrors()
see
getFirstError()
Return values
array<string|int, mixed>

the first errors. The array keys are the attribute names, and the array values are the corresponding error messages. An empty array will be returned if there is no error.

getIterator()

Returns an iterator for traversing the attributes in the model.

public getIterator() : ArrayIterator

This method is required by the interface [[\IteratorAggregate]].

Attributes
#[ReturnTypeWillChange]
Return values
ArrayIterator

an iterator for traversing the items in the list.

getScenario()

Returns the scenario that this model is used in.

public getScenario() : string

Scenario affects how validation is performed and which attributes can be massively assigned.

Return values
string

the scenario that this model is in. Defaults to [[SCENARIO_DEFAULT]].

getSearchAttributeTypes()

public getSearchAttributeTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

search attribute type map.

getValidators()

Returns all the validators declared in [[rules()]].

public getValidators() : ArrayObject|array<string|int, Validator>

This method differs from [[getActiveValidators()]] in that the latter only returns the validators applicable to the current [[scenario]].

Because this method returns an ArrayObject object, you may manipulate it by inserting or removing validators (useful in model behaviors). For example,

$model->validators[] = $newValidator;
Return values
ArrayObject|array<string|int, Validator>

all the validators declared in the model.

hasErrors()

Returns a value indicating whether there is any validation error.

public hasErrors([string|null $attribute = null ]) : bool
Parameters
$attribute : string|null = null

attribute name. Use null to check all attributes.

Return values
bool

whether there is any error.

hasEventHandlers()

Returns a value indicating whether there is any handler attached to the named event.

public hasEventHandlers(string $name) : bool
Parameters
$name : string

the event name

Return values
bool

whether there is any handler attached to the event.

hasMethod()

Returns a value indicating whether a method is defined.

public hasMethod(string $name[, bool $checkBehaviors = true ]) : bool

A method is defined if:

  • the class has a method with the specified name
  • an attached behavior has a method with the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkBehaviors : bool = true

whether to treat behaviors' methods as methods of this component

Return values
bool

whether the method is defined

hasProperty()

Returns a value indicating whether a property is defined for this component.

public hasProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
see
canSetProperty()
Return values
bool

whether the property is defined

init()

Initializes the object.

public init() : mixed

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

instance()

Returns static class instance, which can be used to obtain meta information.

public static instance([bool $refresh = false ]) : static
Parameters
$refresh : bool = false

whether to re-create static instance even, if it is already cached.

Return values
static

class instance.

isAttributeActive()

Returns a value indicating whether the attribute is active in the current scenario.

public isAttributeActive(string $attribute) : bool
Parameters
$attribute : string

attribute name

Tags
see
activeAttributes()
Return values
bool

whether the attribute is active in the current scenario

isAttributeRequired()

Returns a value indicating whether the attribute is required.

public isAttributeRequired(string $attribute) : bool

This is determined by checking if the attribute is associated with a [[\yii\validators\RequiredValidator|required]] validation rule in the current [[scenario]].

Note that when the validator has a conditional validation applied using [[\yii\validators\RequiredValidator::$when|$when]] this method will return false regardless of the when condition because it may be called be before the model is loaded with data.

Parameters
$attribute : string

attribute name

Return values
bool

whether the attribute is required

isAttributeSafe()

Returns a value indicating whether the attribute is safe for massive assignments.

public isAttributeSafe(string $attribute) : bool
Parameters
$attribute : string

attribute name

Tags
see
safeAttributes()
Return values
bool

whether the attribute is safe for massive assignments

load()

Populates the model with input data.

public load(array<string|int, mixed> $data[, string|null $formName = null ]) : bool

This method provides a convenient shortcut for:

if (isset($_POST['FormName'])) {
    $model->attributes = $_POST['FormName'];
    if ($model->save()) {
        // handle success
    }
}

which, with load() can be written as:

if ($model->load($_POST) && $model->save()) {
    // handle success
}

load() gets the 'FormName' from the model's [[formName()]] method (which you may override), unless the $formName parameter is given. If the form name is empty, load() populates the model with the whole of $data, instead of $data['FormName'].

Note, that the data being populated is subject to the safety check by [[setAttributes()]].

Parameters
$data : array<string|int, mixed>

the data array to load, typically $_POST or $_GET.

$formName : string|null = null

the form name to use to load the data into the model, empty string when form not use. If not set, [[formName()]] is used.

Return values
bool

whether load() found the expected form in $data.

loadMultiple()

Populates a set of models with the data from end user.

public static loadMultiple(array<string|int, mixed> $models, array<string|int, mixed> $data[, string|null $formName = null ]) : bool

This method is mainly used to collect tabular data input. The data to be loaded for each model is $data[formName][index], where formName refers to the value of [[formName()]], and index the index of the model in the $models array. If [[formName()]] is empty, $data[index] will be used to populate each model. The data being populated to each model is subject to the safety check by [[setAttributes()]].

Parameters
$models : array<string|int, mixed>

the models to be populated. Note that all models should have the same class.

$data : array<string|int, mixed>

the data array. This is usually $_POST or $_GET, but can also be any valid array supplied by end user.

$formName : string|null = null

the form name to be used for loading the data into the models. If not set, it will use the [[formName()]] value of the first model in $models. This parameter is available since version 2.0.1.

Return values
bool

whether at least one of the models is successfully populated.

normalize()

Normalizes filter value, replacing raw keys according to [[filterControls]] and [[attributeMap]].

public normalize([bool $runValidation = true ]) : array<string|int, mixed>|bool
Parameters
$runValidation : bool = true

whether to perform validation (calling [[validate()]]) before normalizing the filter. Defaults to true. If the validation fails, no filter will be processed and this method will return false.

Return values
array<string|int, mixed>|bool

normalized filter value, or false if validation fails.

off()

Detaches an existing event handler from this component.

public off(string $name[, callable|null $handler = null ]) : bool

This method is the opposite of [[on()]].

Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.

Parameters
$name : string

event name

$handler : callable|null = null

the event handler to be removed. If it is null, all handlers attached to the named event will be removed.

Tags
see
on()
Return values
bool

if a handler is found and detached

offsetExists()

Returns whether there is an element at the specified offset.

public offsetExists(string $offset) : bool

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like isset($model[$offset]).

Parameters
$offset : string

the offset to check on.

Attributes
#[ReturnTypeWillChange]
Return values
bool

whether or not an offset exists.

offsetGet()

Returns the element at the specified offset.

public offsetGet(string $offset) : mixed

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $value = $model[$offset];.

Parameters
$offset : string

the offset to retrieve element.

Attributes
#[ReturnTypeWillChange]
Return values
mixed

the element at the offset, null if no element is found at the offset

offsetSet()

Sets the element at the specified offset.

public offsetSet(string $offset, mixed $value) : mixed

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $model[$offset] = $value;.

Parameters
$offset : string

the offset to set element

$value : mixed

the element value

Attributes
#[ReturnTypeWillChange]

offsetUnset()

Sets the element value at the specified offset to null.

public offsetUnset(string $offset) : mixed

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like unset($model[$offset]).

Parameters
$offset : string

the offset to unset element

Attributes
#[ReturnTypeWillChange]

on()

Attaches an event handler to an event.

public on(string $name, callable $handler[, mixed $data = null ][, bool $append = true ]) : mixed

The event handler must be a valid PHP callback. The following are some examples:

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

The event handler must be defined with the following signature,

function ($event)

where $event is an [[Event]] object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});
Parameters
$name : string

the event name

$handler : callable

the event handler

$data : mixed = null

the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].

$append : bool = true

whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

Tags
see
off()

onUnsafeAttribute()

This method is invoked when an unsafe attribute is being massively assigned.

public onUnsafeAttribute(string $name, mixed $value) : mixed

The default implementation will log a warning message if YII_DEBUG is on. It does nothing otherwise.

Parameters
$name : string

the unsafe attribute name

$value : mixed

the attribute value

rules()

Returns the validation rules for attributes.

public rules() : array<string|int, mixed>
Return values
array<string|int, mixed>

validation rules

safeAttributes()

Returns the attribute names that are safe to be massively assigned in the current scenario.

public safeAttributes() : array<string|int, string>
Return values
array<string|int, string>

safe attribute names

scenarios()

Returns a list of scenarios and the corresponding active attributes.

public scenarios() : array<string|int, mixed>

An active attribute is one that is subject to validation in the current scenario. The returned array should be in the following format:

[
    'scenario1' => ['attribute11', 'attribute12', ...],
    'scenario2' => ['attribute21', 'attribute22', ...],
    ...
]

By default, an active attribute is considered safe and can be massively assigned. If an attribute should NOT be massively assigned (thus considered unsafe), please prefix the attribute with an exclamation character (e.g. '!rank').

The default implementation of this method will return all scenarios found in the [[rules()]] declaration. A special scenario named [[SCENARIO_DEFAULT]] will contain all attributes found in the [[rules()]]. Each scenario will be associated with the attributes that are being validated by the validation rules that apply to the scenario.

Return values
array<string|int, mixed>

a list of scenarios and the corresponding active attributes.

setAttributes()

Sets the attribute values in a massive way.

public setAttributes(array<string|int, mixed> $values[, bool $safeOnly = true ]) : mixed
Parameters
$values : array<string|int, mixed>

attribute values (name => value) to be assigned to the model.

$safeOnly : bool = true

whether the assignments should only be done to the safe attributes. A safe attribute is one that is associated with a validation rule in the current [[scenario]].

Tags
see
safeAttributes()
see
attributes()

setErrorMessages()

Sets the list of error messages responding to invalid filter structure, in format: `[errorKey => message]`.

public setErrorMessages(array<string|int, mixed>|Closure $errorMessages) : mixed

Message may contain placeholders that will be populated depending on the message context. For each message a {filter} placeholder is available referring to the label for [[filterAttributeName]] attribute.

Parameters
$errorMessages : array<string|int, mixed>|Closure

error messages in [errorKey => message] format, or a PHP callback returning them.

setFilter()

public setFilter(mixed $filter) : mixed
Parameters
$filter : mixed

raw filter value.

setScenario()

Sets the scenario for the model.

public setScenario(string $value) : mixed

Note that this method does not check if the scenario exists or not. The method [[validate()]] will perform this check.

Parameters
$value : string

the scenario that this model is in.

setSearchAttributeTypes()

public setSearchAttributeTypes(array<string|int, mixed>|null $searchAttributeTypes) : mixed
Parameters
$searchAttributeTypes : array<string|int, mixed>|null

search attribute type map.

setSearchModel()

public setSearchModel(Model|array<string|int, mixed>|string|callable $model) : mixed
Parameters
$model : Model|array<string|int, mixed>|string|callable

model instance or its DI compatible configuration.

Tags
throws
InvalidConfigException

on invalid configuration.

toArray()

Converts the model into an array.

public toArray([array<string|int, mixed> $fields = [] ][, array<string|int, mixed> $expand = [] ][, bool $recursive = true ]) : array<string|int, mixed>

This method will first identify which fields to be included in the resulting array by calling [[resolveFields()]]. It will then turn the model into an array with these fields. If $recursive is true, any embedded objects will also be converted into arrays. When embedded objects are [[Arrayable]], their respective nested fields will be extracted and passed to [[toArray()]].

If the model implements the [[Linkable]] interface, the resulting array will also have a _link element which refers to a list of links as specified by the interface.

Parameters
$fields : array<string|int, mixed> = []

the fields being requested. If empty or if it contains '*', all fields as specified by [[fields()]] will be returned. Fields can be nested, separated with dots (.). e.g.: item.field.sub-field $recursive must be true for nested fields to be extracted. If $recursive is false, only the root fields will be extracted.

$expand : array<string|int, mixed> = []

the additional fields being requested for exporting. Only fields declared in [[extraFields()]] will be considered. Expand can also be nested, separated with dots (.). e.g.: item.expand1.expand2 $recursive must be true for nested expands to be extracted. If $recursive is false, only the root expands will be extracted.

$recursive : bool = true

whether to recursively return array representation of embedded objects.

Return values
array<string|int, mixed>

the array representation of the object

trigger()

Triggers an event.

public trigger(string $name[, Event|null $event = null ]) : mixed

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.

Parameters
$name : string

the event name

$event : Event|null = null

the event instance. If not set, a default [[Event]] object will be created.

validate()

Performs the data validation.

public validate([array<string|int, string>|string|null $attributeNames = null ][, bool $clearErrors = true ]) : bool

This method executes the validation rules applicable to the current [[scenario]]. The following criteria are used to determine whether a rule is currently applicable:

  • the rule must be associated with the attributes relevant to the current scenario;
  • the rules must be effective for the current scenario.

This method will call [[beforeValidate()]] and [[afterValidate()]] before and after the actual validation, respectively. If [[beforeValidate()]] returns false, the validation will be cancelled and [[afterValidate()]] will not be called.

Errors found during the validation can be retrieved via [[getErrors()]], [[getFirstErrors()]] and [[getFirstError()]].

Parameters
$attributeNames : array<string|int, string>|string|null = null

attribute name or list of attribute names that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated.

$clearErrors : bool = true

whether to call [[clearErrors()]] before performing validation

Tags
throws
InvalidArgumentException

if the current scenario is unknown.

Return values
bool

whether the validation is successful without any error.

validateFilter()

Validates filter attribute value to match filer condition specification.

public validateFilter() : mixed

validateMultiple()

Validates multiple models.

public static validateMultiple(array<string|int, mixed> $models[, array<string|int, mixed>|null $attributeNames = null ]) : bool

This method will validate every model. The models being validated may be of the same or different types.

Parameters
$models : array<string|int, mixed>

the models to be validated

$attributeNames : array<string|int, mixed>|null = null

list of attribute names that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated.

Return values
bool

whether all models are valid. False will be returned if one or multiple models have validation error.

buildAttributeCondition()

Builds search condition for a particular attribute.

protected buildAttributeCondition(string $attribute, mixed $condition) : array<string|int, mixed>
Parameters
$attribute : string

search attribute name.

$condition : mixed

search condition.

Return values
array<string|int, mixed>

actual condition.

buildBlockCondition()

Builds block condition, which consists of a single condition.

protected buildBlockCondition(string $operator, mixed $condition) : array<string|int, mixed>

It covers such operators as not.

Parameters
$operator : string

operator keyword.

$condition : mixed

raw condition.

Return values
array<string|int, mixed>

actual condition.

buildCondition()

protected buildCondition(array<string|int, mixed> $condition) : array<string|int, mixed>
Parameters
$condition : array<string|int, mixed>
Return values
array<string|int, mixed>

built condition.

buildConjunctionCondition()

Builds conjunction condition, which consists of multiple independent ones.

protected buildConjunctionCondition(string $operator, mixed $condition) : array<string|int, mixed>

It covers such operators as and and or.

Parameters
$operator : string

operator keyword.

$condition : mixed

raw condition.

Return values
array<string|int, mixed>

actual condition.

buildInternal()

Performs actual filter build.

protected buildInternal() : mixed
Return values
mixed

built actual filter value.

buildOperatorCondition()

Builds an operator condition.

protected buildOperatorCondition(string $operator, mixed $condition, string $attribute) : array<string|int, mixed>
Parameters
$operator : string

operator keyword.

$condition : mixed

attribute condition.

$attribute : string

attribute name.

Return values
array<string|int, mixed>

actual condition.

defaultErrorMessages()

Returns default values for [[errorMessages]].

protected defaultErrorMessages() : array<string|int, mixed>
Return values
array<string|int, mixed>

default error messages in [errorKey => message] format.

detectSearchAttributeType()

Detect attribute type from given validator.

protected detectSearchAttributeType(Validator $validator) : string|null
Parameters
$validator : Validator

validator from which to detect attribute type.

Tags
since
2.0.14
Return values
string|null

detected attribute type.

detectSearchAttributeTypes()

Composes default value for [[searchAttributeTypes]] from the [[searchModel]] validation rules.

protected detectSearchAttributeTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

attribute type map.

extractFieldsFor()

Extract 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".

protected extractFieldsFor(array<string|int, mixed> $fields, string $rootField) : array<string|int, mixed>
Parameters
$fields : array<string|int, mixed>

The fields requested for extraction

$rootField : string

The root field for which we want to extract the nested fields

Tags
since
2.0.14
Return values
array<string|int, mixed>

nested fields extracted for the given field

extractRootFields()

Extracts the root field names from nested fields.

protected extractRootFields(array<string|int, mixed> $fields) : array<string|int, mixed>

Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "item".

Parameters
$fields : array<string|int, mixed>

The fields requested for extraction

Tags
since
2.0.14
Return values
array<string|int, mixed>

root fields extracted from the given nested fields

filterAttributeValue()

Validates attribute value in the scope of [[searchModel]], applying attribute value filters if any.

protected filterAttributeValue(string $attribute, mixed $value) : mixed
Parameters
$attribute : string

attribute name.

$value : mixed

attribute value.

Return values
mixed

filtered attribute value.

parseErrorMessage()

Parses content of the message from [[errorMessages]], specified by message key.

protected parseErrorMessage(string $messageKey[, array<string|int, mixed> $params = [] ]) : string
Parameters
$messageKey : string

message key.

$params : array<string|int, mixed> = []

params to be parsed into the message.

Return values
string

composed message string.

resolveFields()

Determines which fields can be returned by [[toArray()]].

protected resolveFields(array<string|int, mixed> $fields, array<string|int, mixed> $expand) : array<string|int, mixed>

This method will first extract the root fields from the given fields. Then it will check the requested root fields against those declared in [[fields()]] and [[extraFields()]] to determine which fields can be returned.

Parameters
$fields : array<string|int, mixed>

the fields being requested for exporting

$expand : array<string|int, mixed>

the additional fields being requested for exporting

Return values
array<string|int, mixed>

the list of fields to be exported. The array keys are the field names, and the array values are the corresponding object property names or PHP callables returning the field values.

validateAttributeCondition()

Validates search condition for a particular attribute.

protected validateAttributeCondition(string $attribute, mixed $condition) : mixed
Parameters
$attribute : string

search attribute name.

$condition : mixed

search condition.

validateAttributeValue()

Validates attribute value in the scope of [[model]].

protected validateAttributeValue(string $attribute, mixed $value) : mixed
Parameters
$attribute : string

attribute name.

$value : mixed

attribute value.

validateBlockCondition()

Validates block condition that consists of a single condition.

protected validateBlockCondition(string $operator, mixed $condition) : mixed

This covers such operators as not.

Parameters
$operator : string

raw operator control keyword.

$condition : mixed

raw condition.

validateCondition()

Validates filter condition.

protected validateCondition(mixed $condition) : mixed
Parameters
$condition : mixed

raw filter condition.

validateConjunctionCondition()

Validates conjunction condition that consists of multiple independent ones.

protected validateConjunctionCondition(string $operator, mixed $condition) : mixed

This covers such operators as and and or.

Parameters
$operator : string

raw operator control keyword.

$condition : mixed

raw condition.

validateOperatorCondition()

Validates operator condition.

protected validateOperatorCondition(string $operator, mixed $condition[, string|null $attribute = null ]) : mixed
Parameters
$operator : string

raw operator control keyword.

$condition : mixed

attribute condition.

$attribute : string|null = null

attribute name.

attachBehaviorInternal()

Attaches a behavior to this component.

private attachBehaviorInternal(string|int $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
Parameters
$name : string|int

the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.

$behavior : string|array<string|int, mixed>|Behavior

the behavior to be attached

Return values
Behavior

the attached behavior.

normalizeComplexFilter()

Normalizes complex filter recursively.

private normalizeComplexFilter(array<string|int, mixed> $filter) : array<string|int, mixed>
Parameters
$filter : array<string|int, mixed>

raw filter.

Return values
array<string|int, mixed>

normalized filter.


        
On this page

Search results