2016-03-02 70 views
0

我創建了一個客戶表單。Symfony映射子表格

CustomerType

$builder 
    ->add('username', 'text', array(
     'label' => 'customer.form.email', 
    )) 
    ->add('plainPassword', 'text', array(
     'label' => 'customer.form.password', 
    )) 
    ->add('address', new AddressType) 
; 

要輸入我想使用第二種形式的地址。

地址類型

類包含一個形式字段。 默認: 'data_class'=> '客戶捆綁\實體\地址' 提交表單後

結果

Customer: 
#id: 0 
#username: 'test' 
... 
#address: ArrayCollection 

我需要:

Customer: 
#id: 0 
#username: 'test' 
... 
#address: Address 

有一個簡單的方法到這個解決方案?

+0

您是否嘗試過這個設置http://stackoverflow.com/questions/14853709/embed-one-form -into-another-symfony2? –

+0

請爲您的客戶實體和地址類型提供代碼。 ..它應該沒有集聚,除非你把它映射到實體上作爲集合(例如多對某事) – nakashu

回答

0

我找到了解決辦法:

->add('address', $this->addressType, array(
    'data_class' => 'CustomerBundle\Entity\Address', 
)) 

data_class必須在客戶類型