reg = new RegValidator($reg);
$errors = $this->validator()->validate($reg);
if (count($errors) > 0) {
$errorsString = (string) $errors;
throw new HttpException(521,$errorsString );
}
结果是:
"对象(NameSpace \ Bundle \ Validator \ RegValidator).email:\ n此值不应为空。\ n
但我想表明 电子邮件:此值不应为空 如果我有超过一个这样的","他们之间
答案 0 :(得分:0)
ConstraintViolationList
的结果为$this->validator()->validate($reg);
。因此,您可以按照自己想要的方式格式化字符串。
if (count($errors) > 0) {
$errorStrings = '';
foreach ($errors as $error) {
$errorStrings[] = sprintf("%s: %s\n", $error->getPropertyPath(), $error->getMessage());
}
$errorString = implode(', ', $errorStrings);
throw new HttpException(521, $errorsString);
}