我想學習如何在symfony的3 建立形式下面一些教程,最佳實踐我已經建立了一個PersonTypeSymfony的3 - 爲concating形式塊
class PersonType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('gender', ChoiceType::class, array('label' => 'Anrede', 'choices' => array('Herr' => 'Herr', 'Frau' => 'Frau'), 'attr' => array('class' => 'form-control')))
->add('title', TextType::class, array('label' => 'Titel', 'attr' => array('class' => 'form-control')))
->add('firstname', TextType::class, array('label' => 'Vorname', 'attr' => array('class' => 'form-control')))
->add('lastname', TextType::class, array('label' => 'Nachname', 'attr' => array('class' => 'form-control')))
->add('birthdate', DateType::class, array('label' => 'Geburtsdatum', 'attr' => array('class' => 'form-control')))
->add('street', TextType::class, array('label' => 'Straße', 'attr' => array('class' => 'form-control')))
->add('streetnumber', TextType::class, array('label' => 'Hausnummer', 'attr' => array('class' => 'form-control')))
->add('zip', TextType::class, array('label' => 'PLZ', 'attr' => array('class' => 'form-control')))
->add('city', TextType::class, array('label' => 'Stadt', 'attr' => array('class' => 'form-control')))
->add('email', TextType::class, array('label' => 'E-Mail', 'attr' => array('class' => 'form-control')));
}
public function getName() {
return 'person';
}
}
和一些其他類型。
在控制器我有
$person = new Person();
$form = $this->createForm(PersonType::class, $person);
我現在的問題是,如何我現在CONCAT的PersonType一些其他類型得到一個表出來的嗎?然後,我如何設置提交按鈕?
嗨,謝謝你的回答。我tryingand搜索網頁,但是當我做了'$ resolver-> setDefaults(陣列( \t \t \t \t 'inherit_data'=>真 \t \t \t \t));'所描述的,我得到一個錯誤* *編譯錯誤:AppBundle \ Form \ LocationType :: configureOptions()聲明必須與Symfony \ Component \ Form \ FormTypeInterface :: configureOptions兼容(Symfony \ Component \ OptionsResolver \ OptionsResolver $ resolver)** – JohnPoe
我覺得你忘了'使用Symfony \ Component \ OptionsResolver \ OptionsResolver;'在你的LocationType.php;) – Alsatian
其實我沒有''inherit_data'=> true'解決了這個問題..但是我必須在父實體中創建getters&setters ..現在它工作:) ..謝謝兄弟;) – JohnPoe