educacionController.php 3.92 KB
<?php

namespace UBV\PracticaBundle\Controller;

use UBV\PracticaBundle\Entity\educacion;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;

/**
 * Educacion controller.
 *
 * @Route("educacion")
 */
class educacionController extends Controller
{
    /**
     * Lists all educacion entities.
     *
     * @Route("/", name="educacion_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $educacions = $em->getRepository('UBVPracticaBundle:educacion')->findAll();

        return $this->render('educacion/index.html.twig', array(
            'educacions' => $educacions,
        ));
    }

    /**
     * Creates a new educacion entity.
     *
     * @Route("/new", name="educacion_new")
     * @Method({"GET", "POST"})
     */
    public function newAction(Request $request)
    {
        $educacion = new Educacion();
        $form = $this->createForm('UBV\PracticaBundle\Form\educacionType', $educacion);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($educacion);
            $em->flush();

            return $this->redirectToRoute('educacion_show', array('id' => $educacion->getId()));
        }

        return $this->render('educacion/new.html.twig', array(
            'educacion' => $educacion,
            'form' => $form->createView(),
        ));
    }

    /**
     * Finds and displays a educacion entity.
     *
     * @Route("/{id}", name="educacion_show")
     * @Method("GET")
     */
    public function showAction(educacion $educacion)
    {
        $deleteForm = $this->createDeleteForm($educacion);

        return $this->render('educacion/show.html.twig', array(
            'educacion' => $educacion,
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Displays a form to edit an existing educacion entity.
     *
     * @Route("/{id}/edit", name="educacion_edit")
     * @Method({"GET", "POST"})
     */
    public function editAction(Request $request, educacion $educacion)
    {
        $deleteForm = $this->createDeleteForm($educacion);
        $editForm = $this->createForm('UBV\PracticaBundle\Form\educacionType', $educacion);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrine()->getManager()->flush();

            return $this->redirectToRoute('educacion_edit', array('id' => $educacion->getId()));
        }

        return $this->render('educacion/edit.html.twig', array(
            'educacion' => $educacion,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Deletes a educacion entity.
     *
     * @Route("/{id}", name="educacion_delete")
     * @Method("DELETE")
     */
    public function deleteAction(Request $request, educacion $educacion)
    {
        $form = $this->createDeleteForm($educacion);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($educacion);
            $em->flush();
        }

        return $this->redirectToRoute('educacion_index');
    }

    /**
     * Creates a form to delete a educacion entity.
     *
     * @param educacion $educacion The educacion entity
     *
     * @return \Symfony\Component\Form\Form The form
     */
    private function createDeleteForm(educacion $educacion)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('educacion_delete', array('id' => $educacion->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
}