简体   繁体   English

Symfony2:fos_user_bundle与实体一起嵌入注册表

[英]Symfony2: fos_user_bundle embedding registration form with entity

I've got 3 entities: - overriden User - Address - Company 我有3个实体:-覆盖用户-地址-公司

User Entity got entity fields Address and Company. 用户实体获得了实体字段地址和公司。

Now I'm trying to build User Registration Form using as well fields from Address and Company entities. 现在,我尝试使用“地址”和“公司”实体中的字段来构建“用户注册表”。 The problem is - I have no idea how to proceed with this. 问题是-我不知道如何进行此操作。

I was trying to do sth like this: 我试图做这样的事情:

 $this->addCommonFields($builder);
    $builder
        ->add('company', 'entity', array(
            'label' => 'street',
            'class' => 'AcmePsoBundle:Company',
            'property' => 'street',
        ));

but then I receive dropdown list and it supposed to be textfield. 但随后我收到了下拉列表,它应该是文本字段。

@Edit: Should I use DataTransformer? @Edit:我应该使用DataTransformer吗?

You should create new form type for your AcmePsoBundle:Company entity, and use it as: 您应该为AcmePsoBundle:Company实体创建新的表单类型,并将其用作:

$builder->add('company', new YourCompanyFormType());

YourCompanyFormType.php example: YourCompanyFormType.php示例:

class YourCompanyFormType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add(
            'street',
            'text'
        );
    }

And don't forget to set empty Company to new user entity $user->setCompany(new Company()); 并且不要忘记将空公司设置为新用户实体$ user-> setCompany(new Company());。 before form. 表格之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM