CollectionType
を使用してsymfony 3で巨大なフォームを作成しようとしています。私は複数のサブフォームを定義しなければならず、複数のサブフォームを定義する必要があります。入れ子フォームフィールドへのアクセス(フォームコレクションの埋め込み)
これはそのための私にformTypeです:
public function buildRegistrationForm(FormBuilderInterface $builder, array $options) {
$builder->add('userRegistration', CollectionType::class, [
'entry_type' => UserRegistrationType::class,
'entry_options' => ['label' => true],
]);
$builder->add('meters', CollectionType::class, [
'entry_type' => MeterType::class,
'entry_options' => ['label' => true],
'allow_add' => true,
]);
...
}
は今、私はビューのCollectionTypeはフィールドにアクセスしてみてください。
{{ form_label(registrationForm.email, null, {'label_attr': {'class': 'form-label'}}) }}
{{ form_widget(registrationForm.email, {'attr': {'class': 'form-control'}}) }}
が、私はエラーを取得する:このためのコードがある
Neither the property "email" nor one of the methods "email()", "getemail()"/"isemail()"/"hasemail()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".
私は「symfonyはメインフォーム(registrationForm
)から直接電子メールのフィールドを取得しようとしますが、私はドンことを知っていますサブフォームにアクセスする方法を知っています。ドキュメント(http://symfony.com/doc/current/form/form_collections.html)には、registrationForm.userRegistration.email
を使用してサブフォームに簡単にアクセスできると記載されています。しかし、これは私にエラーを与える:
Neither the property "userRegistration" nor one of the methods ...
私はどのようにビュー内のサブフィールドにアクセスできますか?