0

I had a problem while saving data of conflict entity and it failed every time the methods is called.

$em->persist($conflict);

return back a blank screen and show a string 'persist'. I don't know how to solve it as I am new to symfony2.

Here is my sample code on create conflict controller.

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()));
}
2
  • Do you have any eventlistener / event subscriber? Does this entity "conflict" have any method a"PostUpdate" "PrePersist" etc? If this is the only code you wrote, looks all right (maybe something funky on the form "conflictType") so it must be something about our symfony2 installation Commented Jul 10, 2014 at 0:17
  • agree with @Francesc ... sounds like die(); to test if some part of the code was reached Commented Jul 14, 2014 at 13:33

1 Answer 1

1

There may be few concern:

If u r using latest version of symfony i. e. (Symfony2.2 or more latest) then :

$form->bindRequest($request);

should be :

$form->handleRequest($request);

and also in return rendering line

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

You are rendering just your id while you should pass a object to render the all field of object .. It may be like this :

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

also i do't understand mandatory to pass the

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

in your form creation like

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

It may be like this

   $form = $this->createForm(new ConflictType(), $conflict);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank I will check your suggestion and let you know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.