formform在表单事件上为空 [英] Entity is empty in formModifier on form events
问题描述
我的母语不是我的母语。
English is not my native language, sorry for that.
我有一个会议实体(rendezVous),在这个实体中,我有两个其他映射实体医生docteur)和客户(客户)。
I have a meet entity (rendezVous) and in this entity, i have two others mapped entities doctor(docteur) and customer(client).
我想在选择客户时更改医生名单。
I want to change the list of doctors when choosing a customer.
为此,我在我的RendezVousType中创建一个表单事件,但问题是当我选择一个客户时,客户端实体在我的formModifier中为空。
For that, I create a form events in my RendezVousType, but the problem is when i choose a customer, the Client entity is empty in my formModifier.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('client', EntityType::class, array(
'class' => 'AppBundle:Client',
'placeholder' => '',
));
$formModifier = function (FormInterface $form, Client $client = null) {
$idEspece = null === $client ? 0 : $client->getId();
$form->add('docteur', EntityType::class, array(
'class' => 'AppBundle:Docteur',
'placeholder' => '',
'query_builder' => function (DocteurRepository $er) use ($idEspece) {
return $er->getByClientEspece($idEspece);
},
));
};
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier) {
$data = $event->getData();
$formModifier($event->getForm(), $data->getClient());
}
);
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($formModifier) {
$client = $event->getForm()->getData();
$formModifier($event->getForm()->getParent(), $client);
}
);
}
当我为$ idEspece设置默认值时,查询构建器返回正确的列表。
When I set a default value for $idEspece, the query builder returns the correct list.
推荐答案
感谢您的帮助,但我自己解决了我的问题,只需要做一个
Thanks for you help, but I solved my issue by myself by simply doing a
php app/console cache:clear
对不起,如果你放弃了这个时间这个
I'm sorry, if you loose your time for this
PS:我按照此关于symfony doc的教程,用于创建表单事件。
PS: I followed this tutorial on symfony doc for create form events.
这篇关于formform在表单事件上为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!