0
我用下面的代码获取表单中的所有错误:Symfony的2.1 FOSUser翻译错误消息
// get all the errors in the form in an array
public static function getErrorMessages(\Symfony\Component\Form\Form $form) {
$errors = array();
// actual errors
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
// find children that are not valid
if ($form->count()>0) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = formHelper::getErrorMessages($child);
}
}
}
工程。唯一的问题是FOSUser:我已经定义了我的验证组,并且错误没有被翻译。而不是得到“密码太短”我得到“fos_user.password.short”。问题是与行:
$errors[] = $error->getMessage();
这不会转换错误。任何人都可以帮我解决这个问题?