当我使用choice_value函数以排除我的选择中的某些数据时,如果该字段为空,则将值设置为数据库,但不设置为“ NULL”。此值是我实体的第一个条目。当我列出所有数据时,如果该字段为空,则会在数据库中设置“ Null”值。
有什么想法吗?
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->currentId = $options['currentId'];
$builder
->add('oldOwners', entityType::class, array(
'class' => OldOwners::class,
'required' => false,
'empty_data' => null,
'multiple' => false,
'choice_value' => function (OldOwners $oldOwners = null) {
if ($oldOwners != null && $oldOwners != '') {
if ($this->currentId != 0 && $oldOwners->animal->getId() == $this->currentId)
return $oldOwners->getDateDisposal()->format('Y-m-d');
}
},
'choice_label' => function (OldOwners $oldOwners = null) {
if ($oldOwners != null && $oldOwners != '') {
if ($this->currentId != 0 && $oldOwners->animal->getId() == $this->currentId)
return $oldOwners->getDateDisposal()->format('Y-m-d');
}
},
'label' => "Date"));
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Adopting::class,
'currentId' => null,
]);
$resolver->setRequired('currentId');
}