使用symfony2.1。
我确实在 Form/RegisterUser.php 中构建了一个表单
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add(
'email',
'email',
array('attr' => array('placeholder' => 'email.placeholder')));
$builder->add(
'password',
'repeated',
array(
'first_name' => 'password',
'second_name' => 'confirm',
'type' => 'password',
'invalid_message' => 'register.password.repeat', ));
$builder->add("t_and_c", "checkbox", array("mapped" => false, ));
// "True" validator on the form for t&c
$builder->addValidator(new CallbackValidator( function(FormInterface $form) {
if (!$form["t_and_c"]->getData()) {
$form->addError(new FormError('Please accept the terms and conditions in order to register'));
}
}));
}
/**
* Returns the default options for this form type.
* @param array $options
* @return array The default options
*/
public function getDefaultOptions(array $options) {
return array('data_class' => 'Frontend\AccountBundle\Entity\User');
}
在 app/Ressources/translation/validators.LANG.yml 中:
<trans-unit id="6">
<source>email.placeholder</source>
<target>Enter email.</target>
</trans-unit>
<trans-unit id="12">
<source>register.password.repeat</source>
<target>Passwords don't match.</target>
</trans-unit>
字段 invalid_message 将被翻译,而不是字段 email.placeholder。有错误吗?我不使用树枝并进行正常渲染。