如何将标签添加到表单生成器中(而不是在树枝中)?
我有这段代码,但它不起作用:
$builder->add('name','text',array(
'label' => 'Due Date',
));
我在 fosuserbundle 中遇到的问题,我有 overring 表单
<?php
namespace Acme\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
// add your custom field
$builder->add('name','text',array(
'label' => 'Due Date',
));
parent::buildForm($builder, $options);
}
public function getName()
{
return 'acme_user_registration';
}
}
但不起作用,不给我任何错误并设置标签“fos_user_registration_form_name”
I have this code, but it doesn't work:
$builder->add('name','text',array(
'label' => 'Due Date',
));
the problem i have in fosuserbundle, i have overring form
<?php
namespace Acme\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
// add your custom field
$builder->add('name','text',array(
'label' => 'Due Date',
));
parent::buildForm($builder, $options);
}
public function getName()
{
return 'acme_user_registration';
}
}
but not work, not give me any error and set the label "fos_user_registration_form_name"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会看到标签为
fos_user_registration_form_name
,因为FOSUserBundle
使用翻译文件来翻译其中的所有文本。您必须将翻译添加到名为
Resources/translations/FOSUserBundle.nb.yml
的文件中(例如挪威语),或者您可以修改捆绑包附带的翻译文件(将其复制到Acme\ UserBundle
是一个更好的方法)。You see label as
fos_user_registration_form_name
, becauseFOSUserBundle
uses translations files to translate all texts in it.You have to add your translations to file called like
Resources/translations/FOSUserBundle.nb.yml
(example for norwegian) or you can modify translations file coming with the bundle (copying it toAcme\UserBundle
is a better way).