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 に答える