おはようございます。
田端と申します。
Symfony2でForm/Typeを使用フォームの作成をしているのですが
1つのbuildFormを2つに分けたりしたいのですがそういう指定はできるのでしょうか?
わかりにくいのですが、下記のやり方でTypeにbuildFormとは別にbuildFormAddressを別で作成しています。
このbuildFormAddressを読みにいく様にしたいです。
# Contoller側
// 普通の書き方
$this->form = $this->createForm(new ExampleType());
// 読みに行きたいけどエラーになる書き方
$type = new ExampleType();
$this->form = $this->createForm($type->buildFormAddress());
# Type側
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text', ['label' => '企業名'])
->add('ruby', 'text', ['label' => 'ふりがな']);
}
public function buildFormAddress(FormBuilderInterface $builder, array $options)
{
$builder
->add('zip', 'text', ['label' => '郵便番号'])
->add('address', 'text', ['label' => '住所']);
}
何かアドバイスいただけると助かります。
宜しくお願い致します。