【发布时间】:2018-04-20 01:49:15
【问题描述】:
我有一个疯狂的问题,我不明白。
我关心的代码是这样的:
public function appendAction(Request $request, $pKpPatientid)
{
if (!$this->isAdmin()) {
throw new AccessDeniedException();
}
$entity = new DataDFu1();
$entity1 = $this->getDoctrine()
->getRepository('DataLiveBundle:DataAPatient')
->find($pKpPatientid);
$appendForm = $this->createAppendForm($pKpPatientid,$entity, $entity1);
$appendForm->handleRequest($request);
// if ($appendForm->isValid()) {
if($appendForm->get('submit')->isClicked()){//Save
//return $this->redirect($this->generateUrl('dataapatient_sendMessage', array("pKpPatientid" => $pKpPatientid)));
$entity->setFu1KfPatientid($entity1);
$this->storeAppendDataDFu1($entity);
// }
}
return $this->render('DataLiveBundle:DataDFu1:form.html.twig', array(
// 'entity' => $entity,
'form' => $appendForm->createView(),
'isNew'=> true,
));
}
/**
* The function createAppendForm
* Creates a form with the Information from a DataAPatient.
* @param DataAPatient $pKpPatientid The primary key
* @return \Symfony\Component\Form\Form
*/
private function createAppendForm($pKpPatientid, $entity, $entity1)
{
$form = $this->createForm($this->get('data_livebundle.form.dataapatienttype'), $entity1, array(
//'action' => $this->generateUrl('dataHome'),
'method' => 'POST'
));
$form->add('submit', 'submit', array('label' => 'Create Fu1'));
return $form->add('dFu1', new DataDFu1Type(), array('data'=>$entity));
}
/**
* The function storeEditedDataDFu1
* Persists changes made to an existing DataDFu1 entity to the database
* @param DataDFu1 entity
* @return DataAPatient $pKpPatientid The primary key
*/
public function storeAppendDataDFu1($entity)
{
$em = $this->getDoctrine()->getManager();
$session = $this->getRequest()->getSession();
if (!$entity) {
throw $this->createNotFoundException('Unable to find DataDFu1 entity.');
}
$em->persist($entity);
$em->flush();
$session->getFlashBag()->add(
'notice',
'Your changes to the DataDFu1 of ID: "'."xyz". '" was saved!'
);
// return $entity->getPKpPatientid();
}
我创建了一个包含两个带有实体的表单并呈现它的表单。它工作得很好。但是在这个时刻,当想要存储(storeAppendDataDFu1)来自实体的数据并且只是来自这个实体时,entity1 会丢失以前在表单中可视化的所有值(只是可视化的)。这意味着这个 entity1 显示的字段以 NULL 值永久存储在数据库中。
即使只为 entity1 () 编程了一个记忆函数,entity1 怎么能持久存储错误的值???
我的假设是它与表单星座有关,因为每当我按下提交时,entity1 的字段都会设置为 NULL。
我希望有人知道这个问题:),我真的找不到解决方案。 *entity 和 entity1 只是连接在一起,因为 entity 的外键是 entity1 的主键,它是 oneToOne 匹配...
我还发现mappingBy null?那是什么意思?会是这个原因吗?
oneToOne:
fu1KfPatientid:
targetEntity: DataAPatient
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: dFu1
joinColumns:
_FU1_kf_PatientID:
referencedColumnName: __P_kp_PatientID
orphanRemoval: false
感谢您的反馈...如果您需要更多信息,请告诉我...谢谢
【问题讨论】:
标签: php symfony doctrine symfony-2.1