diff --git a/framework/validators/ExistValidator.php b/framework/validators/ExistValidator.php index 75fe8298eb..6479395410 100644 --- a/framework/validators/ExistValidator.php +++ b/framework/validators/ExistValidator.php @@ -97,11 +97,13 @@ class ExistValidator extends Validator $params = [$targetAttribute => $object->$attribute]; } - foreach ($params as $value) { - if (!$this->allowArray && is_array($value)) { - $this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.')); + if (!$this->allowArray) { + foreach ($params as $value) { + if (is_array($value)) { + $this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.')); - return; + return; + } } }