2016-06-28 5 views
0
reg = new RegValidator($reg); 

$errors = $this->validator()->validate($reg); 




if (count($errors) > 0) { 
      $errorsString = (string) $errors; 

      throw new HttpException(521,$errorsString); 
     } 

結果は次のとおりです。印刷symfonyのバリデーションクラス-nice列

「オブジェクト(ネームスペース\バンドル\バリ\ RegValidator).email:\ nは、この値を空白にするべきではありません\ nは

私は 電子メールを表示したいと思います:この値は を空白にすべきではないと私はそれらの間「」

答えて

0

を持つので、より多くのそして1を持っている場合は、$this->validator()->validate($reg);の結果としてConstraintViolationListを持っているあなたは、文字列の書式を設定することができますので。あなたが望む方法で。

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); 
}