Метод | Описание | |
---|---|---|
__get ( string $name ) : mixed | PHP getter magic method. | |
__isset ( string $name ) : boolean | Checks if a property value is null. | |
__set ( string $name, mixed $value ) | PHP setter magic method. | |
__unset ( string $name ) | Sets a component property to be null. | |
afterDelete ( ) | This method is invoked after deleting a record. | |
afterFind ( ) | This method is called when the AR object is created and populated with the query result. | |
afterRefresh ( ) | This method is called when the AR object is refreshed. | |
afterSave ( boolean $insert, array $changedAttributes ) | This method is called at the end of inserting or updating a record. | |
beforeDelete ( ) : boolean | This method is invoked before deleting a record. | |
beforeSave ( boolean $insert ) : boolean | This method is called at the beginning of inserting or updating a record. | |
canGetProperty ( $name, $checkVars = true, $checkBehaviors = true ) | ||
canSetProperty ( $name, $checkVars = true, $checkBehaviors = true ) | ||
delete ( ) : integer | false | Deletes the table row corresponding to this active record. | |
deleteAll ( string | array $condition = '', array $params = [] ) : integer | Deletes rows in the table using the provided conditions. | |
equals ( yii\db\ActiveRecordInterface $record ) : boolean | Returns a value indicating whether the given active record is the same as the current one. | |
extraFields ( ) | ||
fields ( ) | ||
findAll ( $condition ) : static[] | ||
findOne ( $condition ) : static | ||
getAttribute ( string $name ) : mixed | Returns the named attribute value. | |
getAttributeHint ( string $attribute ) : string | Returns the text hint for the specified attribute. | |
getAttributeLabel ( string $attribute ) : string | Returns the text label for the specified attribute. | |
getDirtyAttributes ( string[] | null $names = null ) : array | Returns the attribute values that have been modified since they are loaded or saved most recently. | |
getIsNewRecord ( ) : boolean | Returns a value indicating whether the current record is new. | |
getOldAttribute ( string $name ) : mixed | Returns the old value of the named attribute. | |
getOldAttributes ( ) : array | Returns the old attribute values. | |
getOldPrimaryKey ( boolean $asArray = false ) : mixed | Returns the old primary key value(s). | |
getPrimaryKey ( boolean $asArray = false ) : mixed | Returns the primary key value(s). | |
getRelatedRecords ( ) : array | Returns all populated related records. | |
getRelation ( string $name, boolean $throwException = true ) : yii\db\ActiveQueryInterface | |
Returns the relation object with the specified name. | |
hasAttribute ( string $name ) : boolean | Returns a value indicating whether the model has an attribute with the specified name. | |
hasMany ( string $class, array $link ) : yii\db\ActiveQueryInterface | Declares a has-many relation. | |
hasOne ( string $class, array $link ) : yii\db\ActiveQueryInterface | Declares a has-one relation. | |
init ( ) | Initializes the object. | |
instantiate ( array $row ) : static | Creates an active record instance. | |
isAttributeChanged ( string $name, boolean $identical = true ) : boolean | Returns a value indicating whether the named attribute has been changed. | |
isPrimaryKey ( array $keys ) : boolean | Returns a value indicating whether the given set of attributes represents the primary key for this model | |
isRelationPopulated ( string $name ) : boolean | Check whether the named relation has been populated with records. | |
link ( string $name, yii\db\ActiveRecordInterface $model, array $extraColumns = [] ) | Establishes the relationship between two models. | |
markAttributeDirty ( string $name ) | Marks an attribute dirty. | |
offsetExists ( mixed $offset ) : boolean | Returns whether there is an element at the specified offset. | |
offsetUnset ( mixed $offset ) | Sets the element value at the specified offset to null. | |
optimisticLock ( ) : string | Returns the name of the column that stores the lock version for implementing optimistic locking. | |
populateRecord ( |
Populates an active record object using a row of data from the database/storage. | |
populateRelation ( string $name, yii\db\ActiveRecordInterface | array | null $records ) | Populates the named relation with the related records. | |
refresh ( ) : boolean | Repopulates this active record with the latest data. | |
save ( boolean $runValidation = true, array $attributeNames = null ) : boolean | Saves the current record. | |
setAttribute ( string $name, mixed $value ) | Sets the named attribute value. | |
setIsNewRecord ( boolean $value ) | Sets the value indicating whether the record is new. | |
setOldAttribute ( string $name, mixed $value ) | Sets the old value of the named attribute. | |
setOldAttributes ( array | null $values ) | Sets the old attribute values. | |
unlink ( string $name, yii\db\ActiveRecordInterface $model, boolean $delete = false ) | Destroys the relationship between two models. | |
unlinkAll ( string $name, boolean $delete = false ) | Destroys the relationship in current model. | |
update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false | Saves the changes to this active record into the associated database table. | |
updateAll ( array $attributes, string | array $condition = '' ) : integer | Updates the whole table using the provided attribute values and conditions. | |
updateAllCounters ( array $counters, string | array $condition = '' ) : integer | Updates the whole table using the provided counter changes and conditions. | |
updateAttributes ( array $attributes ) : integer | Updates the specified attributes. | |
updateCounters ( array $counters ) : boolean | Updates one or several counter columns for the current AR object. |
Метод | Описание | |
---|---|---|
findByCondition ( mixed $condition ) : yii\db\ActiveQueryInterface | Finds ActiveRecord instance(s) by the given condition. | |
updateInternal ( array $attributes = null ) : integer | false |
Метод | Описание | |
---|---|---|
bindModels ( array $link, yii\db\ActiveRecordInterface $foreignModel, yii\db\ActiveRecordInterface $primaryModel ) |
public afterDelete ( ) |
public afterFind ( ) |
public afterRefresh ( ) |
public afterSave ( boolean $insert, array $changedAttributes ) | ||
$insert | boolean | whether this method called while inserting a record. If `false`, it means the method is called while updating a record. |
$changedAttributes | array | The old values of attributes that had changed and were saved. You can use this parameter to take action based on the changes made for example send an email when the password had changed or implement audit trail that tracks all the changes. `$changedAttributes` gives you the old attribute values while the active record (`$this`) has already the new, updated values. Note that no automatic type conversion performed by default. You may use [[\yii\behaviors\AttributeTypecastBehavior]] to facilitate attribute typecasting. See http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#attributes-typecasting. |
public beforeDelete ( ) : boolean | ||
Результат | boolean | whether the record should be deleted. Defaults to `true`. |
public beforeSave ( boolean $insert ) : boolean | ||
$insert | boolean | whether this method called while inserting a record. If `false`, it means the method is called while updating a record. |
Результат | boolean | whether the insertion or updating should continue. If `false`, the insertion or updating will be cancelled. |
public canGetProperty ( $name, $checkVars = true, $checkBehaviors = true ) |
public canSetProperty ( $name, $checkVars = true, $checkBehaviors = true ) |
public static deleteAll ( string | array $condition = '', array $params = [] ) : integer | ||
$condition | string | array | the conditions that will be put in the WHERE part of the DELETE SQL. Please refer to [[Query::where()]] on how to specify this parameter. |
$params | array | the parameters (name => value) to be bound to the query. |
Результат | integer | the number of rows deleted |
public static findAll ( $condition ) : static[] | ||
Результат | static[] | an array of ActiveRecord instances, or an empty array if nothing matches. |
protected static findByCondition ( mixed $condition ) : yii\db\ActiveQueryInterface | ||
$condition | mixed | please refer to [[findOne()]] for the explanation of this parameter |
Результат | yii\db\ActiveQueryInterface | the newly created [[ActiveQueryInterface|ActiveQuery]] instance. |
public static findOne ( $condition ) : static | ||
Результат | static | ActiveRecord instance matching the condition, or `null` if nothing matches. |
public getAttribute ( string $name ) : mixed | ||
$name | string | the attribute name |
Результат | mixed | the attribute value. `null` if the attribute is not set or does not exist. |
public getAttributeHint ( string $attribute ) : string | ||
$attribute | string | the attribute name |
Результат | string | the attribute hint |
public getAttributeLabel ( string $attribute ) : string | ||
$attribute | string | the attribute name |
Результат | string | the attribute label |
public getDirtyAttributes ( string[] | null $names = null ) : array | ||
$names | string[] | null | the names of the attributes whose values may be returned if they are changed recently. If null, [[attributes()]] will be used. |
Результат | array | the changed attribute values (name-value pairs) |
public getIsNewRecord ( ) : boolean | ||
Результат | boolean | whether the record is new and should be inserted when calling [[save()]]. |
public getOldAttribute ( string $name ) : mixed | ||
$name | string | the attribute name |
Результат | mixed | the old attribute value. `null` if the attribute is not loaded before or does not exist. |
public getOldAttributes ( ) : array | ||
Результат | array | the old attribute values (name-value pairs) |
public getOldPrimaryKey ( boolean $asArray = false ) : mixed | ||
$asArray | boolean | whether to return the primary key value as an array. If `true`, the return value will be an array with column name as key and column value as value. If this is `false` (default), a scalar value will be returned for non-composite primary key. |
Результат | mixed | the old primary key value. An array (column name => column value) is returned if the primary key is composite or `$asArray` is `true`. A string is returned otherwise (null will be returned if the key value is null). |
public getPrimaryKey ( boolean $asArray = false ) : mixed | ||
$asArray | boolean | whether to return the primary key value as an array. If `true`, the return value will be an array with column names as keys and column values as values. Note that for composite primary keys, an array will always be returned regardless of this parameter value. |
Результат | mixed | the primary key value. An array (column name => column value) is returned if the primary key is composite or `$asArray` is `true`. A string is returned otherwise (null will be returned if the key value is null). |
public getRelatedRecords ( ) : array | ||
Результат | array | an array of related records indexed by relation names. |
public getRelation ( string $name, boolean $throwException = true ) : yii\db\ActiveQueryInterface | |
||
$name | string | the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive). |
$throwException | boolean | whether to throw exception if the relation does not exist. |
Результат | yii\db\ActiveQueryInterface | |
the relational query object. If the relation does not exist and `$throwException` is `false`, `null` will be returned. |
public hasAttribute ( string $name ) : boolean | ||
$name | string | the name of the attribute |
Результат | boolean | whether the model has an attribute with the specified name. |
public hasMany ( string $class, array $link ) : yii\db\ActiveQueryInterface | ||
$class | string | the class name of the related record |
$link | array | the primary-foreign key constraint. The keys of the array refer to the attributes of the record associated with the `$class` model, while the values of the array refer to the corresponding attributes in **this** AR class. |
Результат | yii\db\ActiveQueryInterface | the relational query object. |
public hasOne ( string $class, array $link ) : yii\db\ActiveQueryInterface | ||
$class | string | the class name of the related record |
$link | array | the primary-foreign key constraint. The keys of the array refer to the attributes of the record associated with the `$class` model, while the values of the array refer to the corresponding attributes in **this** AR class. |
Результат | yii\db\ActiveQueryInterface | the relational query object. |
public init ( ) |
public static instantiate ( array $row ) : static | ||
$row | array | row data to be populated into the record. |
Результат | static | the newly created active record |
public isAttributeChanged ( string $name, boolean $identical = true ) : boolean | ||
$name | string | the name of the attribute. |
$identical | boolean | whether the comparison of new and old value is made for identical values using `===`, defaults to `true`. Otherwise `==` is used for comparison. This parameter is available since version 2.0.4. |
Результат | boolean | whether the attribute has been changed |
public static isPrimaryKey ( array $keys ) : boolean | ||
$keys | array | the set of attributes to check |
Результат | boolean | whether the given set of attributes represents the primary key for this model |
public isRelationPopulated ( string $name ) : boolean | ||
$name | string | the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive). |
Результат | boolean | whether relation has been populated with records. |
public link ( string $name, yii\db\ActiveRecordInterface $model, array $extraColumns = [] ) | ||
$name | string | the case sensitive name of the relationship, e.g. `orders` for a relation defined via `getOrders()` method. |
$model | yii\db\ActiveRecordInterface | the model to be linked with the current one. |
$extraColumns | array | additional column values to be saved into the junction table. This parameter is only meaningful for a relationship involving a junction table (i.e., a relation set with [[ActiveRelationTrait::via()]] or [[ActiveQuery::viaTable()]].) |
public markAttributeDirty ( string $name ) | ||
$name | string | the attribute name |
public offsetExists ( mixed $offset ) : boolean | ||
$offset | mixed | the offset to check on |
Результат | boolean | whether there is an element at the specified offset. |
public offsetUnset ( mixed $offset ) | ||
$offset | mixed | the offset to unset element |
public optimisticLock ( ) : string | ||
Результат | string | the column name that stores the lock version of a table row. If `null` is returned (default implemented), optimistic locking will not be supported. |
public static populateRecord ( |
||
$record | the record to be populated. In most cases this will be an instance created by [[instantiate()]] beforehand. | |
$row | array | attribute values (name => value) |
public populateRelation ( string $name, yii\db\ActiveRecordInterface | array | null $records ) | ||
$name | string | the relation name, e.g. `orders` for a relation defined via `getOrders()` method (case-sensitive). |
$records | yii\db\ActiveRecordInterface | array | null | the related records to be populated into the relation. |
public save ( boolean $runValidation = true, array $attributeNames = null ) : boolean | ||
$runValidation | boolean | whether to perform validation (calling [[validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`. |
$attributeNames | array | list of attribute names that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved. |
Результат | boolean | whether the saving succeeded (i.e. no validation errors occurred). |
public setAttribute ( string $name, mixed $value ) | ||
$name | string | the attribute name |
$value | mixed | the attribute value. |
public setIsNewRecord ( boolean $value ) | ||
$value | boolean | whether the record is new and should be inserted when calling [[save()]]. |
public setOldAttribute ( string $name, mixed $value ) | ||
$name | string | the attribute name |
$value | mixed | the old attribute value. |
public setOldAttributes ( array | null $values ) | ||
$values | array | null | old attribute values to be set. If set to `null` this record is considered to be [[isNewRecord|new]]. |
public unlink ( string $name, yii\db\ActiveRecordInterface $model, boolean $delete = false ) | ||
$name | string | the case sensitive name of the relationship, e.g. `orders` for a relation defined via `getOrders()` method. |
$model | yii\db\ActiveRecordInterface | the model to be unlinked from the current one. You have to make sure that the model is really related with the current model as this method does not check this. |
$delete | boolean | whether to delete the model that contains the foreign key. If `false`, the model's foreign key will be set `null` and saved. If `true`, the model containing the foreign key will be deleted. |
public update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false | ||
$runValidation | boolean | whether to perform validation (calling [[validate()]]) before saving the record. Defaults to `true`. If the validation fails, the record will not be saved to the database and this method will return `false`. |
$attributeNames | array | list of attribute names that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved. |
Результат | integer | false | the number of rows affected, or `false` if validation fails or [[beforeSave()]] stops the updating process. |
public static updateAll ( array $attributes, string | array $condition = '' ) : integer | ||
$attributes | array | attribute values (name-value pairs) to be saved into the table |
$condition | string | array | the conditions that will be put in the WHERE part of the UPDATE SQL. Please refer to [[Query::where()]] on how to specify this parameter. |
Результат | integer | the number of rows updated |
public static updateAllCounters ( array $counters, string | array $condition = '' ) : integer | ||
$counters | array | the counters to be updated (attribute name => increment value). Use negative values if you want to decrement the counters. |
$condition | string | array | the conditions that will be put in the WHERE part of the UPDATE SQL. Please refer to [[Query::where()]] on how to specify this parameter. |
Результат | integer | the number of rows updated |
public updateAttributes ( array $attributes ) : integer | ||
$attributes | array | the attributes (names or name-value pairs) to be updated |
Результат | integer | the number of rows affected. |
public updateCounters ( array $counters ) : boolean | ||
$counters | array | the counters to be updated (attribute name => increment value) Use negative values if you want to decrement the counters. |
Результат | boolean | whether the saving is successful |
protected updateInternal ( array $attributes = null ) : integer | false | ||
$attributes | array | attributes to update |
Результат | integer | false | the number of rows affected, or false if [[beforeSave()]] stops the updating process. |