yii\validators\CompareValidator::validateAttribute PHP Метод

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

public validateAttribute ( $model, $attribute )
    public function validateAttribute($model, $attribute)
    {
        $value = $model->{$attribute};
        if (is_array($value)) {
            $this->addError($model, $attribute, Yii::t('yii', '{attribute} is invalid.'));
            return;
        }
        if ($this->compareValue !== null) {
            $compareLabel = $compareValue = $compareValueOrAttribute = $this->compareValue;
        } else {
            $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
            $compareValue = $model->{$compareAttribute};
            $compareLabel = $compareValueOrAttribute = $model->getAttributeLabel($compareAttribute);
        }
        if (!$this->compareValues($this->operator, $this->type, $value, $compareValue)) {
            $this->addError($model, $attribute, $this->message, ['compareAttribute' => $compareLabel, 'compareValue' => $compareValue, 'compareValueOrAttribute' => $compareValueOrAttribute]);
        }
    }

Usage Example

Пример #1
0
 /**
  * @param $attribute
  */
 public function validatePassword($attribute)
 {
     if (empty($this->password)) {
         return;
     }
     $StringValidator = new StringValidator(['min' => 6]);
     $StringValidator->validateAttribute($this, 'password');
     $CompareValidator = new CompareValidator(['compareAttribute' => 'password']);
     $CompareValidator->validateAttribute($this, 'repassword');
 }
All Usage Examples Of yii\validators\CompareValidator::validateAttribute