我有这个表格+控制器http://pastebin.com/wLPyXvbj
当我向DB(新数据)添加数据时,它们正在工作但我在编辑时遇到了麻烦,我在这里尽我所能解释。
我编辑EVERY SINGLE FIELD,数据在DB OK上更新。
我尝试编辑FEW字段,只编辑我希望用户编辑的字段,而不是编辑所有内容。可以更新的字段可以毫无问题地插入到数据库中,但是其他字段,我不希望用户修改而不是保留DB中的旧值(因为它们没有更改),它们都变为空值。
所以“选择性编辑”而不是“所有字段编辑”都有问题,但我找不到问题...我无法创建所有字段编辑表单,因为其中一些是静态的,没有编辑
这是我用于编辑操作的控制器,因为您可以看到它与newAction
public function agentupdateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$comments = new VtigerTicketcomments();
$session = $this->get("session");
$proyecto = $session->get('proyecto');
$assets = $session->get('assets');
$contacts = $em->createQuery('SELECT u.contactid, u.email, u.phone, u.mobile FROM WbsGoclientsBundle:VtigerContactdetails u')->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
foreach($assets as $a)
$uuids[$a['UUID']] = $a['UUID'];
$entity = $em->getRepository('WbsGoclientsBundle:VtigerTicketcf')->find($id);
$ticket = $entity->getId();
$solution = $ticket->getSolution();
$ticketcfForm = $this->createForm(new TicketcfType($uuids, $session->get('contacts'), $session->get('rol'), $session->get('tecnicos')), $entity);
$ticketcfForm->submit($request);
if($ticketcfForm->isValid())
{
$data = $ticketcfForm->getData();
if($ticket->getStatus() == 'Closed')
{
if(!$ticket->getSolution())
$ticket->setSolution($solution);
$workflow = new ComVtigerWorkflowtaskQueue();
$workflow->setTaskid('9');
$workflow->setEntityid('9x'.$id);
$workflow->setDoafter('0');
$em->persist($workflow);
$em->flush();
$hoy = new \DateTime();
if($ticketcf->getFReso() == null)
$ticketcf->setFReso($hoy->format('d-m-Y H:i:s'));
}
$em->persist($ticket);
$em->flush();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('tickets_show', array('id' => $ticket->getTicketNo())));
}
return $this->render('WbsGoclientsBundle:Tickets:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'rol' => $session->get('rol'),
'ticket_form' => $ticketForm->createView(),
));
}