草庐IT

CountryRepository

全部标签

php - Symfony 如何验证 EntityType 字段

我的UserType表单上有这个EntityType字段:publicfunctionbuildForm(FormBuilderInterface$builder,array$options){$builder->add('country',EntityType::class,array('class'=>Country::class,'choice_label'=>'nicename'));}我如何使用验证约束以用户只能在国家表的所有行范围内选择一个值的方式来验证这种类型的字段?我认为我应该使用带有回调的Choice约束,并在我的CountryRepository类中调用getAll