PHP Трейт yii\db\QueryTrait

It is supposed to be used in a class that implements the QueryInterface.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Автор: Carsten Brandt ([email protected])
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$emulateExecution whether to emulate the actual query execution, returning empty or false results.
$indexBy string | callable
$limit maximum number of records to be returned. If not set or less than 0, it means no limit.
$offset zero-based offset from where the records are to be returned. If not set or less than 0, it means starting from the beginning.
$orderBy how to sort the query results. This is used to construct the ORDER BY clause in a SQL statement. The array keys are the columns to be sorted by, and the array values are the corresponding sort directions which can be either SORT_ASC or SORT_DESC. The array may also contain [[Expression]] objects. If that is the case, the expressions will be converted into strings without any change.
$where query condition. This refers to the WHERE clause in a SQL statement. For example, ['age' => 31, 'team' => 1].

Открытые методы

Метод Описание
addOrderBy ( string | array | yii\db\Expression $columns ) Adds additional ORDER BY columns to the query.
andFilterWhere ( array $condition ) Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
andWhere ( string | array $condition ) Adds an additional WHERE condition to the existing one.
emulateExecution ( boolean $value = true ) Sets whether to emulate query execution, preventing any interaction with data storage.
filterWhere ( array $condition ) Sets the WHERE part of the query but ignores [[isEmpty()|empty operands]].
indexBy ( string | callable $column ) Sets the [[indexBy]] property.
limit ( integer $limit ) Sets the LIMIT part of the query.
offset ( integer $offset ) Sets the OFFSET part of the query.
orFilterWhere ( array $condition ) Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
orWhere ( string | array $condition ) Adds an additional WHERE condition to the existing one.
orderBy ( string | array | yii\db\Expression $columns ) Sets the ORDER BY part of the query.
where ( string | array $condition ) Sets the WHERE part of the query.

Защищенные методы

Метод Описание
filterCondition ( array $condition ) : array Removes [[isEmpty()|empty operands]] from the given query condition.
isEmpty ( mixed $value ) : boolean Returns a value indicating whether the give value is "empty".
normalizeOrderBy ( array | string | yii\db\Expression $columns ) : array Normalizes format of ORDER BY data

Описание методов

addOrderBy() публичный Метод

Adds additional ORDER BY columns to the query.
См. также: orderBy()
public addOrderBy ( string | array | yii\db\Expression $columns )
$columns string | array | yii\db\Expression the columns (and the directions) to be ordered by. Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. `['id' => SORT_ASC, 'name' => SORT_DESC]`). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression). Note that if your order-by is an expression containing commas, you should always use an array to represent the order-by information. Otherwise, the method will not be able to correctly determine the order-by columns. Since version 2.0.7, an [[Expression]] object can be passed to specify the ORDER BY part explicitly in plain SQL.

andFilterWhere() публичный Метод

The new condition and the existing one will be joined using the 'AND' operator. This method is similar to QueryTrait::andWhere. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users.
См. также: filterWhere()
См. также: orFilterWhere()
public andFilterWhere ( array $condition )
$condition array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

andWhere() публичный Метод

The new condition and the existing one will be joined using the 'AND' operator.
См. также: where()
См. также: orWhere()
public andWhere ( string | array $condition )
$condition string | array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

emulateExecution() публичный Метод

After this mode is enabled, methods, returning query results like [[one()]], [[all()]], [[exists()]] and so on, will return empty or false values. You should use this method in case your program logic indicates query should not return any results, like in case you set false where condition like 0=1.
С версии: 2.0.11
public emulateExecution ( boolean $value = true )
$value boolean whether to prevent query execution.

filterCondition() защищенный Метод

Removes [[isEmpty()|empty operands]] from the given query condition.
protected filterCondition ( array $condition ) : array
$condition array the original condition
Результат array the condition with [[isEmpty()|empty operands]] removed.

filterWhere() публичный Метод

This method is similar to QueryTrait::where. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users. The following code shows the difference between this method and QueryTrait::where: php WHERE age=:age $query->filterWhere(['name' => null, 'age' => 20]); WHERE age=:age $query->where(['age' => 20]); WHERE name IS NULL AND age=:age $query->where(['name' => null, 'age' => 20]); Note that unlike QueryTrait::where, you cannot pass binding parameters to this method.
См. также: where()
См. также: andFilterWhere()
См. также: orFilterWhere()
public filterWhere ( array $condition )
$condition array the conditions that should be put in the WHERE part. See [[where()]] on how to specify this parameter.

indexBy() публичный Метод

Sets the [[indexBy]] property.
public indexBy ( string | callable $column )
$column string | callable the name of the column by which the query results should be indexed by. This can also be a callable (e.g. anonymous function) that returns the index value based on the given row data. The signature of the callable should be: ```php function ($row) { // return the index value corresponding to $row } ```

isEmpty() защищенный Метод

The value is considered "empty", if one of the following conditions is satisfied: - it is null, - an empty string (''), - a string containing only whitespace characters, - or an empty array.
protected isEmpty ( mixed $value ) : boolean
$value mixed
Результат boolean if the value is empty

limit() публичный Метод

Sets the LIMIT part of the query.
public limit ( integer $limit )
$limit integer the limit. Use null or negative value to disable limit.

normalizeOrderBy() защищенный Метод

Normalizes format of ORDER BY data
protected normalizeOrderBy ( array | string | yii\db\Expression $columns ) : array
$columns array | string | yii\db\Expression the columns value to normalize. See [[orderBy]] and [[addOrderBy]].
Результат array

offset() публичный Метод

Sets the OFFSET part of the query.
public offset ( integer $offset )
$offset integer the offset. Use null or negative value to disable offset.

orFilterWhere() публичный Метод

The new condition and the existing one will be joined using the 'OR' operator. This method is similar to QueryTrait::orWhere. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users.
См. также: filterWhere()
См. также: andFilterWhere()
public orFilterWhere ( array $condition )
$condition array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

orWhere() публичный Метод

The new condition and the existing one will be joined using the 'OR' operator.
См. также: where()
См. также: andWhere()
public orWhere ( string | array $condition )
$condition string | array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

orderBy() публичный Метод

Sets the ORDER BY part of the query.
См. также: addOrderBy()
public orderBy ( string | array | yii\db\Expression $columns )
$columns string | array | yii\db\Expression the columns (and the directions) to be ordered by. Columns can be specified in either a string (e.g. `"id ASC, name DESC"`) or an array (e.g. `['id' => SORT_ASC, 'name' => SORT_DESC]`). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression). Note that if your order-by is an expression containing commas, you should always use an array to represent the order-by information. Otherwise, the method will not be able to correctly determine the order-by columns. Since version 2.0.7, an [[Expression]] object can be passed to specify the ORDER BY part explicitly in plain SQL.

where() публичный Метод

See [[QueryInterface::where()]] for detailed documentation.
См. также: andWhere()
См. также: orWhere()
public where ( string | array $condition )
$condition string | array the conditions that should be put in the WHERE part.

Описание свойств

$emulateExecution публичное свойство

whether to emulate the actual query execution, returning empty or false results.
См. также: emulateExecution()
С версии: 2.0.11
public $emulateExecution

$indexBy публичное свойство

public string|callable $indexBy
Результат string | callable

$limit публичное свойство

maximum number of records to be returned. If not set or less than 0, it means no limit.
public $limit

$offset публичное свойство

zero-based offset from where the records are to be returned. If not set or less than 0, it means starting from the beginning.
public $offset

$orderBy публичное свойство

how to sort the query results. This is used to construct the ORDER BY clause in a SQL statement. The array keys are the columns to be sorted by, and the array values are the corresponding sort directions which can be either SORT_ASC or SORT_DESC. The array may also contain [[Expression]] objects. If that is the case, the expressions will be converted into strings without any change.
public $orderBy

$where публичное свойство

query condition. This refers to the WHERE clause in a SQL statement. For example, ['age' => 31, 'team' => 1].
См. также: where() for valid syntax on specifying this value.
public $where