我希望用户选择"car_types"中列出的汽车类型。第一个表。选择车型(轿车/卡车)后,将解锁与所选车型相关联的车辆品牌选择。选择汽车品牌后,将解锁与该品牌相关的车型选择。等等…
这是我的表模式:这是我的代码搜索表单:
class SearchCarsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('typ',EntityType::class,[
'class' => CarTypes::class,
'choice_label' => 'name'
])
->add('mark',EntityType::class,[
'class' => Brand::class,
'choice_label' => 'name'
])
->add('model',EntityType::class,[
'class' => Models::class,
'choice_label' => 'name'
])
->add('generation',EntityType::class,[
'class' => Generations::class,
'choice_label' => 'name'
])
->add('car_body',EntityType::class,[
'class' => CarBodys::class,
'choice_label' => 'name'
])
->add('engine',EntityType::class,[
'class' => Engines::class,
'choice_label' => 'name'
])
->add('equipment',EntityType::class,[
'class' => Equipment::class,
'choice_label' => 'name'
])
->add('Submit',SubmitType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}
我在一段时间前遇到了同样的问题,我能找到的解决方案是创建由ajax
请求提供的选择输入。例如:用户选择汽车类型/卡车,然后将ajax request
变为your controller
,并将卡车类型的品牌返回到您的树枝模板中。所以你的整个页面没有重新加载,但只有一部分被重新加载,并获得品牌。等等,你可以用javascript