Symfony 如何删除找不到实体错误?

Symfony 如何删除找不到实体错误?,symfony,doctrine-orm,entitymanager,Symfony,Doctrine Orm,Entitymanager,我创建了控制器的更新函数,但当我在字段中插入值并提交异常返回时,我创建了控制器的更新函数,但当我在字段中插入值并提交异常返回时 "Unable to find Sections entity" 这是我的控制器代码: public function updateAction(Request $request, $id) { if(isset($_SESSION['id'])) { $proposalid=$_SESSION['id']; }

我创建了控制器的更新函数,但当我在字段中插入值并提交异常返回时,我创建了控制器的更新函数,但当我在字段中插入值并提交异常返回时

 "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(),
    ));
}
公共函数更新操作(请求$Request,$id)
{
如果(isset($\u会话['id'])){
$proposalid=$\会话['id'];
}
$user=$this->get('security.context')->getToken()->getUser();
$userId=$user->getId();
$em=$this->getDoctrine()->getManager();
$entity=$em->getRepository('ProposalsProposalsBundle:Sections')->find($id);
if(!$entity){
抛出$this->createNotFoundException('无法找到实体');
}
$deleteForm=$this->createDeleteForm($id);
$editForm=$this->createForm(新的SectionsType(),$entity);
$editForm->bind($request);
$sectioncounter=$request->request->get('sectioncounter');
$date=new\DateTime();
$query=$em->createQuery(“从ProposalsProposalsBundle中删除:s节,其中s.proposalID='”“$proposalID.”);
$ids=$query->getResult();
如果($request->isXmlHttpRequest()){
$response=新响应();
对于($i=0;$isetSectionName($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();
} 
返回$response;
}
返回$this->render('ProposalsProposalsBundle:Sections:edit.html.twig',数组(
“实体”=>$entity,
“编辑表单”=>$editForm->createView(),
'delete_form'=>$deleteForm->createView(),
));
}

如何删除此异常?

Symfony2有自己的会话处理程序。要设置会话变量:

$session = $this->getRequest()->getSession();
$session->set('member', $member);
$session = $this->getRequest()->getSession();
$member = $session->get('member');
要获取会话变量,请执行以下操作:

$session = $this->getRequest()->getSession();
$session->set('member', $member);
$session = $this->getRequest()->getSession();
$member = $session->get('member');

你应该检查你的实体和存储库文件。我想问题一定在那里,你确定你有一个具有该id的分区吗?是的,我确定分区具有该id