php - Creating Forms with Joins in Symfony 2 -


now i'm trying create forms symfony 2 formbuilder. have table "client" join on table "address".

i want form fields of client , fields of address.

all fields should textfields.

thats im done far, i'm wondering if best practice or if theres better way solve this.

i created table address type , added in client type.

the client type used formbuilder.

addresstype.php

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('street')         ->add('company'); }  public function setdefaultoptions(optionsresolverinterface $resolver) {     $resolver->setdefaults(array(         'data_class' => 'test\userbundle\entity\address',     )); }  public function getname() {     return 'address'; } 

clienttype.php

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('title')         ->add('address', new addresstype()); }  public function setdefaultoptions(optionsresolverinterface $resolver) {     $resolver->setdefaults(array(         'data_class' => 'test\userbundle\entity\client',     )); }  public function getname() {     return 'client'; } 

for me, looks best practice, consists in using embedded forms. can find more here :

http://symfony.com/doc/current/book/forms.html#embedded-forms


Comments