我要嵌入的預充電的非實體形式的集合,這裏是代碼,第一個是父窗體buildForm方法。如何嵌入的非實體形式的預充電集合中的Symfony2
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add("example1")->add("example2");
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/*some logic to do before adding the collection of forms*/
$form->add('aclAccess', 'collection', array(
'type' => new ChildFormType(),
'allow_add' => true,
'mapped' => false,
'data' => /* I dont know how to precharge a collection of non-entity forms*/
));
});
}
現在孩子形式
public function buildForm (FormBuilderInterface $builder, array $options) {
$builder->add("test1", "text", array("read_only" => true, "data" => "test"));
$builder->->add("test2", "choice", array(
'choices' => array('opt1' => 'Opt1', 'opt2' => 'Opt2'),
'multiple' => true,
'expanded' => true
));
}
所以basicly我要管理的test2的領域這些子選項分離的形式,每個選項組將取決於TEST1字段的值,我知道這可以通過編寫沒有形式類的樹枝中的所有東西來完成,但我認爲表單類是運行phpunit測試的最佳實踐,用於可維護性等...