Forms 我可以通过从controller到formType的选项传递自己的数组吗
我想通过此函数传递数组: $form=$this->createForm(ProductTypeType::class,$productType,$options)Forms 我可以通过从controller到formType的选项传递自己的数组吗,forms,symfony4,Forms,Symfony4,我想通过此函数传递数组: $form=$this->createForm(ProductTypeType::class,$productType,$options) 在symfony4中,不可能通过$otions将自己的参数传递给formType。如您所述。以下是一个例子: $form = $this->createForm( EntityType::class, $entity, ['optionOne' => true] //this is the arr
在symfony4中,不可能通过$otions将自己的参数传递给formType。如您所述。以下是一个例子:
$form = $this->createForm(
EntityType::class,
$entity,
['optionOne' => true] //this is the array of options (in this case just one)
);
在EntityType
中,您可以像这样使用此选项(例如,添加字段):
另外,在EntityType
中,不要忘记为您的选项设置默认值:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Entity::class,
'optionOne' => false,
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Entity::class,
'optionOne' => false,
]);
}