| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 
 |  
/**
     * Displays a form to edit an existing Comment entity.
     *
     * @Route("/{id}/edit", name="site_front_comment_edit")
     * @Method("GET")
     * @Template()
     */
    public function editAction($id) {
        $em = $this->getDoctrine()->getManager();
 
        $entity = $em->getRepository('SiteFrontBundle:Comment')->find($id);
 
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Comment entity.');
        }
 
        $editForm = $this->createEditForm($entity);
        $deleteForm = $this->createDeleteForm($id);
 
        return $this->render('SiteFrontBundle:Comment:edit.html.twig', array(
                    'entity' => $entity,
                    'edit_form' => $editForm->createView(),
                    'delete_form' => $deleteForm->createView(),
        ));
    }
 
    /**
     * Creates a form to edit a Comment entity.
     *
     * @param Comment $entity The entity
     *
     * @return \Symfony\Component\Form\Form The form
     */
    private function createEditForm(Comment $entity) {
        $form = $this->createForm(new CommentType(), $entity, array(
            'action' => $this->generateUrl('site_front_comment_update', array('id' => $entity->getId())),
            'method' => 'PUT',
        ));
 
        $form->add('submit', 'submit', array('label' => 'Modifier', 'attr' => array('class' => 'btn btn-success')));
 
        return $form;
    }
 
    /**
     * Edits an existing Comment entity.
     *
     * @Route("/{id}", name="site_front_comment_update")
     * @Method("PUT")
     * @Template("SiteFrontBundle:Comment:edit.html.twig")
     */
    public function updateAction(Request $request, $id) {
        $em = $this->getDoctrine()->getManager();
 
        $entity = $em->getRepository('SiteFrontBundle:Comment')->find($id);
 
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Comment entity.');
        }
 
        $deleteForm = $this->createDeleteForm($id);
        $editForm = $this->createEditForm($entity);
        $editForm->handleRequest($request);
 
        if ($editForm->isValid()) {
            $em->flush();
 
            return $this->redirect($this->generateUrl('site_front_comment_edit', array('id' => $id)));
        }
 
        return array(
            'entity' => $entity,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView()
        );
 
    } | 
Partager