Symfony/Silex: 删除验证消息的前缀和后缀(代码[...])
Symfony/Silex: Remove prefix and suffix (code [...]) of validation message
我可以更改验证消息,甚至可以使用翻译组件进行翻译。
$errors = $app['validator']->validate($email, new Assert\Email(array(
'message' => 'The email "{{ value }}" is not a valid email.'
)));
但是还是在消息前添加了字段内容,在消息后添加了一些代码:
foobar : The email "foobar" ist not a valid email. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)
如何删除两者,以便只有普通消息?
验证方法的return值是一个列表对象。当您将其转换为字符串时,内置 'toString' 方法会向错误字符串添加前缀和后缀。
解决方案是遍历错误并调用 getMessage 方法:
foreach ($errors as $error) {
echo $error->getMessage().'<br>';
}
我可以更改验证消息,甚至可以使用翻译组件进行翻译。
$errors = $app['validator']->validate($email, new Assert\Email(array(
'message' => 'The email "{{ value }}" is not a valid email.'
)));
但是还是在消息前添加了字段内容,在消息后添加了一些代码:
foobar : The email "foobar" ist not a valid email. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)
如何删除两者,以便只有普通消息?
验证方法的return值是一个列表对象。当您将其转换为字符串时,内置 'toString' 方法会向错误字符串添加前缀和后缀。
解决方案是遍历错误并调用 getMessage 方法:
foreach ($errors as $error) {
echo $error->getMessage().'<br>';
}