我制作了控制器的更新功能,但是当我在字段中插入值并提交异常返回时,我制作了控制器的更新功能,但是当我在字段中插入值并提交异常返回时,
"Unable to find Sections entity"
这是我的控制器代码:
public function updateAction(Request $request, $id)
{
if(isset($_SESSION['id'])) {
$proposalid=$_SESSION['id'];
}
$user = $this->get('security.context')->getToken()->getUser();
$userId = $user->getId();
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ProposalsProposalsBundle:Sections')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Sections entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new SectionsType(), $entity);
$editForm->bind($request);
$sectioncounter = $request->request->get('sectioncounter');
$date= new \DateTime();
$query = $em->createQuery("Delete from ProposalsProposalsBundle:Sections s where s.proposalID='".$proposalid."'");
$ids = $query->getResult();
if($request->isXmlHttpRequest()) {
$response = new Response();
for($i=0; $i<$sectioncounter; $i++){
$sectionname = $_POST['sectionName'.$i];
$description=$_POST['description'.$i];
$entity->setSectionName($sectionname);
$entity->setDescription($description);
$entity->setProposalID($proposalid);
$entity->setCreatedBy($userId);
$entity->setUpdatedBy($userId);
$entity->setCreatedDatetime($date);
$entity->setUpdatedDatetime($date);
$em->persist($entity);
$em->flush();
$em->clear();
}
return $response;
}
return $this->render('ProposalsProposalsBundle:Sections:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
如何删除此异常?