0

我制作了控制器的更新功能,但是当我在字段中插入值并提交异常返回时,我制作了控制器的更新功能,但是当我在字段中插入值并提交异常返回时,

 "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(),
    ));
}

如何删除此异常?

4

1 回答 1

0

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

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

获取会话变量:

$session = $this->getRequest()->getSession();
$member = $session->get('member');
于 2013-10-29T13:39:30.817 回答