dssqq82402 2015-09-18 07:25
浏览 30

Symfony2 FOS用户在表单中有多个地址

When a company registers they insert his main office adress data. This data is simply saved in a USer entity. However, If the company has more offices he should be able to add them on the same form, but to a different entity. Is that even possible? If not, what are the options.

For example:

When a user goes to registration the form opens:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);
    $builder

        ->add('country', 'country', array(
            'label' => 'form.label.country',
            'required' => false,
        ))
        ->add('town', 'text', array(
            'label' => 'form.label.town',
            'required' => false,
        ))

        >add('residence', 'text', array(
            'label' => 'form.label.adress',
            'required' => false,
        ))
        ->add('zip', 'text', array(
            'label' => 'form.label.zip',
            'required' => false,
        ))

This is saved in a User class.

If a user has more offices additional fields should appear that store the new data to a different entity.

UserAdress entity:

class UserAdress
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="id_user", type="integer")
     */
    private $idUser;

    /**
     * @var string
     *
     * @ORM\Column(name="office_name", type="string", length=255)
     */
    private $officeName;

    /**
     * @var string
     *
     * @ORM\Column(name="Adress", type="string", length=255)
     */
    private $adress;

    /**
     * @var string
     *
     * @ORM\Column(name="country", type="string", length=255)
     */
    private $country;

    /**
     * @var string
     *
     * @ORM\Column(name="town", type="string", length=255)
     */
    private $town;

    /**
     * @var string
     *
     * @ORM\Column(name="zip", type="string", length=255)
     */
    private $zip;

Now I need to render a new form with these fields in the same registration form... Is that possible?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分