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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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