我有FormBuilder
:
$builder
->add(
'token',
Type\TextType::class,
array(
'required' => true,
'trim' => true,
'attr' => array(),
'constraints' => array(new Assert\NotBlank(array('message' => 'password.notBlank')))
)
)
->add(
'password',
Type\RepeatedType::class,
array(
'type' => Type\PasswordType::class,
'required' => true,
'invalid_message' => 'password.notMatch',
'constraints' => array(
new Assert\NotBlank(array('message' => 'password.notBlank')),
new Assert\Length(
array(
'min' => 8,
'max' => 40,
'minMessage' => 'password.lengthMin',
'maxMessage' => 'password.lengthMax',
)
),
)
)
);
问题是token
字段附加到特定字段,因此我可以通过以下方式获取错误对象:
foreach ($form->all() as $child) {
foreach ($child->getErrors() as $key => $error) ...
但是password
附加到表单本身,所以我唯一能得到错误的方法是:
$errors = $form->getErrors(true, false);
它没有给我任何字段描述信息..我怎样才能覆盖这种行为?