Symfony2:表单集合,自定义标签

时间:2014-01-30 14:51:04

标签: php forms symfony formbuilder

我想知道如何为表单

中的实体集合设置不同的标签

这是我的控制器

        $company = new Company();


    $cf_entry = new CustomFieldEntry();
    $cf_entry->setCustomFieldId(13);
    $company->getCustomFieldEntries()->add($cf_entry);

    $cf_entry2 = new CustomFieldEntry();
    $cf_entry2->setCustomFieldId(14);
    $company->getCustomFieldEntries()->add($cf_entry2);



    $form = $this->createFormBuilder($company)
      ->setAction($this->generateUrl('company_new'))
      ->add('customFieldEntries', 'collection',
        array('type' => new CustomFieldEntryType()))
      ->add('save', 'submit')
      ->getForm();

我的表单类型

class CustomFieldEntryType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('value');
    }

在这种情况下,我希望字段'value'具有不同的标签

谢谢

3 个答案:

答案 0 :(得分:1)

我认为你所寻求的答案是:Symfony2 form collection: Index of the current object is shown

你必须个性化表格。

答案 1 :(得分:0)

传递label名称,如:

class CustomFieldEntryType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('value', 'text', array(
            'label' => 'Your New Label Name',
        ));
    }

此文档The label option对您有用

答案 2 :(得分:0)

只需在此处发布答案(该线程很难找到):Symfony Forms - How to Change a CollectionTypes Items labels