[英]Symfony send options from FormType CollectionType to FormType
I would like to know if there is any way to send an option from a form type with CollectionType
to another form type. 我想知道是否有任何方法可以从具有
CollectionType
的表单类型向另一种表单类型发送选项。
$builder->add(
'contact', CollectionType::class,
[
'entry_type' => ContactType::class,
'data' => [
'options' => 'confirmResa'
]
]
);
I know we can send option with this data
by using $builder->getData()
in the second form type but when it's a CollectionType
, I think it take the data
for him instead of using it for the entry_type
. 我知道我们可以通过在第二种表单类型中使用
$builder->getData()
来发送包含此data
的选项,但是当它是CollectionType
,我认为它为他获取data
而不是将其用于entry_type
。
Ok nevermind I find a solution, I've already use in my last project. 好的,我找不到解决方案,我已经在上一个项目中使用了。
So the answer is to use entry_options
and sending data
in the entry_options
所以答案是使用
entry_options
并在entry_options
发送data
cf: http://symfony.com/doc/current/reference/forms/types/collection.html#entry-options cf: http : //symfony.com/doc/current/reference/forms/types/collection.html#entry-options
Solution: 解:
$builder->add('contact', CollectionType::class, [
'entry_type' => ContactType::class,
'entry_options' => ['data' => ['confirmResa']],
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.