2014-07-10 3 views
0

충돌 엔티티의 데이터를 저장하는 동안 문제가 발생했으며 메소드가 호출 될 때마다 실패했습니다.Symfony2에서 persist 메소드로 데이터 저장 실패

$em->persist($conflict); 

빈 화면으로 돌아가서 'persist'문자열을 표시하십시오. 심포니 2를 처음 접했을 때 그것을 해결하는 방법을 모르겠습니다.

작성 충돌 컨트롤러에 대한 예제 코드는 다음과 같습니다. 유 심포니 난의 최신 버전을 사용 r에 경우

:

public function createAction() { 
    $conflict = new Conflict(); 
    $form = $this->createForm(new ConflictType(), $conflict, array(
     "container" => $this->container, 
     "em" => $this->getDoctrine()->getEntityManager() 
    )); 

    $request = $this->getRequest(); 
    $form->bindRequest($request); 
    if ($form->isValid()) { 
     $conflict->setAwardDeadlineCurrent($conflict->getAwardDeadlineInit()); 
     $em = $this->getDoctrine()->getEntityManager(); 
     $em->persist($conflict); 
     $em->flush(); 
     $request->getSession()->setFlash("notice", "Case has been created"); 
     return $this->redirect($this->generateUrl("acf_case_conflict_edit", array("id" => $conflict->getId()))); 
    } 
    return $this->render("ACFCaseBundle:Conflict:new.html.twig", array("form" => $form->createView())); 
} 
+0

처럼 될 수있다

$form = $this->createForm(new ConflictType(), $conflict, array( "container" => $this->container, "em" => $this->getDoctrine()->getEntityManager() )); 

처럼 양식 작성에

array( "container" => $this->container, "em" => $this->getDoctrine()->getEntityManager() ) 

를 전달하는 필수 이해 do't 당신이 있습니까 어떤의 EventListener/이벤트 가입자? 이 엔티티에 "충돌"에는 "PostUpdate" "PrePersist"등의 메소드가 있습니까? 이것이 여러분이 작성한 유일한 코드라면, symfony2 설치에 관한 것이어야합니다. (아마도 "conflictType"과 같은 형태로 펑키 한 것 같습니다.) – Cesc

+0

@Francesc와 동의합니다 ... die(); 코드의 일부에 도달했는지 테스트합니다. – nixoschu

답변

1

은 몇 가지 문제가있을 수 있습니다. 이자형. (Symfony2.2 이상의 최신) 한 다음 :

$form->bindRequest($request); 

은 다음과 같아야합니다

$form->handleRequest($request); 

도 반환 렌더링 라인에

return $this->redirect($this->generateUrl("acf_case_conflict_edit", array("id" => $conflict->getId()))); 

당신이 통과해야하는 동안 당신은 당신의 ID를 렌더링하는 객체의 모든 필드를 렌더링하는 객체입니다. 다음과 같을 수 있습니다 :

,210

또한 나는이

$form = $this->createForm(new ConflictType(), $conflict); 
+0

감사의 말 귀하의 제안을 확인하고 알려드립니다. –