我可以通过控制器的选项传递一个自己的数组到 formType
Can i pass an own array trough the options from controller to formType
我想通过这个函数传递一个数组:
$form = $this->createForm(ProductTypeType::class, $productType, $options);
在 symfony4 中,不可能通过 $otions 将自己的参数传递给 formType。
按照你的描述是可以的。这是一个例子:
$form = $this->createForm(
EntityType::class,
$entity,
['optionOne' => true] //this is the array of options (in this case just one)
);
在 EntityType
中,您可以像这样使用此选项(例如,添加一个字段):
if($options["optionOne"]){
$builder
->add('addedField')
//....or do something else...
同样在 EntityType
中,不要忘记为您的选项设置默认值:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Entity::class,
'optionOne' => false,
]);
}
我想通过这个函数传递一个数组: $form = $this->createForm(ProductTypeType::class, $productType, $options);
在 symfony4 中,不可能通过 $otions 将自己的参数传递给 formType。
按照你的描述是可以的。这是一个例子:
$form = $this->createForm(
EntityType::class,
$entity,
['optionOne' => true] //this is the array of options (in this case just one)
);
在 EntityType
中,您可以像这样使用此选项(例如,添加一个字段):
if($options["optionOne"]){
$builder
->add('addedField')
//....or do something else...
同样在 EntityType
中,不要忘记为您的选项设置默认值:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Entity::class,
'optionOne' => false,
]);
}