Posted By

saturnxxi on 08/04/13


Tagged

php symfony2


Versions (?)

1 to 1


 / Published in: PHP
 

1 to 1 symfony forms

  1. class UserType extends AbstractType
  2. {
  3.  
  4.  
  5. public function buildForm(FormBuilderInterface $builder, array $options)
  6. {
  7. $builder
  8. ->add('name', 'text', array('label' => 'Name'))
  9.  
  10. ->add(
  11. 'userdata',
  12. new UserData(),
  13.  
  14. 'label' => 'Address'
  15. )
  16. )
  17. ->add('Save', 'submit', array('label' => 'Save'));
  18. }
  19.  
  20. public function setDefaultOptions(OptionsResolverInterface $resolver)
  21. {
  22. $resolver->setDefaults(
  23. 'data_class' => 'My\Bundle\Entity\User'
  24. )
  25. );
  26. }
  27.  
  28. public function getName()
  29. {
  30. return 'usertype';
  31. }
  32. }
  33.  
  34. class UserDataType extends AbstractType
  35. {
  36.  
  37. public function buildForm(FormBuilderInterface $builder, array $options)
  38. {
  39. $builder
  40. ->add('city', 'text', array('label' => 'City'));
  41.  
  42. }
  43.  
  44. public function setDefaultOptions(OptionsResolverInterface $resolver)
  45. {
  46. $resolver->setDefaults(
  47. 'data_class' => 'My\Bundle\Entity\UserData'
  48. )
  49. );
  50. }
  51.  
  52. public function getName()
  53. {
  54. return 'userdata';
  55. }
  56. }

Report this snippet  

You need to login to post a comment.