PHP Класс yii\validators\UniqueValidator

UniqueValidator checks if the value being validated is unique in the table column specified by the ActiveRecord class [[targetClass]] and the attribute [[targetAttribute]]. The following are examples of validation rules using this validator: php a1 needs to be unique ['a1', 'unique'] a1 needs to be unique, but column a2 will be used to check the uniqueness of the a1 value ['a1', 'unique', 'targetAttribute' => 'a2'] a1 and a2 need to be unique together, and they both will receive error message [['a1', 'a2'], 'unique', 'targetAttribute' => ['a1', 'a2']] a1 and a2 need to be unique together, only a1 will receive error message ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']] a1 needs to be unique by checking the uniqueness of both a2 and a3 (using a1 value) ['a1', 'unique', 'targetAttribute' => ['a2', 'a1' => 'a3']]
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends Validator
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$comboNotUnique string
$filter additional filter to be applied to the DB query used to check the uniqueness of the attribute value. This can be a string or an array representing the additional query condition (refer to [[\yii\db\Query::where()]] on the format of query condition), or an anonymous function with the signature function ($query), where $query is the [[\yii\db\Query|Query]] object that you can modify in the function.
$message the user-defined error message. When validating single attribute, it may contain the following placeholders which will be replaced accordingly by the validator: - {attribute}: the label of the attribute being validated - {value}: the value of the attribute being validated When validating mutliple attributes, it may contain the following placeholders: - {attributes}: the labels of the attributes being validated. - {values}: the values of the attributes being validated.
$targetAttribute the name of the ActiveRecord attribute that should be used to validate the uniqueness of the current attribute value. If not set, it will use the name of the attribute currently being validated. You may use an array to validate the uniqueness of multiple columns at the same time. The array values are the attributes that will be used to validate the uniqueness, while the array keys are the attributes whose values are to be validated. If the key and the value are the same, you can just specify the value.
$targetClass the name of the ActiveRecord class that should be used to validate the uniqueness of the current attribute value. If not set, it will use the ActiveRecord class of the attribute being validated.

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

Метод Описание
init ( )
validateAttribute ( $model, $attribute )

Приватные методы

Метод Описание
addComboNotUniqueError ( Model $model, string $attribute ) Builds and adds [[comboNotUnique]] error message to the specified model attribute.

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

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

public init ( )

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

public validateAttribute ( $model, $attribute )

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

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

Устаревший: since version 2.0.10, to be removed in 2.1. Use [[message]] property to setup custom message for multiple target attributes.
С версии: 2.0.9
public string $comboNotUnique
Результат string

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

additional filter to be applied to the DB query used to check the uniqueness of the attribute value. This can be a string or an array representing the additional query condition (refer to [[\yii\db\Query::where()]] on the format of query condition), or an anonymous function with the signature function ($query), where $query is the [[\yii\db\Query|Query]] object that you can modify in the function.
public $filter

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

the user-defined error message. When validating single attribute, it may contain the following placeholders which will be replaced accordingly by the validator: - {attribute}: the label of the attribute being validated - {value}: the value of the attribute being validated When validating mutliple attributes, it may contain the following placeholders: - {attributes}: the labels of the attributes being validated. - {values}: the values of the attributes being validated.
public $message

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

the name of the ActiveRecord attribute that should be used to validate the uniqueness of the current attribute value. If not set, it will use the name of the attribute currently being validated. You may use an array to validate the uniqueness of multiple columns at the same time. The array values are the attributes that will be used to validate the uniqueness, while the array keys are the attributes whose values are to be validated. If the key and the value are the same, you can just specify the value.
public $targetAttribute

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

the name of the ActiveRecord class that should be used to validate the uniqueness of the current attribute value. If not set, it will use the ActiveRecord class of the attribute being validated.
См. также: targetAttribute
public $targetClass