%PDF- %PDF-
Direktori : /home/emtnaeewxm/www/src/EEM/ArticleBundle/Controller/ |
Current File : /home/emtnaeewxm/www/src/EEM/ArticleBundle/Controller/FamilleController.php |
<?php namespace EEM\ArticleBundle\Controller; use EEM\ArticleBundle\Entity\Famille; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; /** * Famille controller. * * @Route("/admin/famille") */ class FamilleController extends Controller { /** * Lists all famille entities. * * @Route("/", name="famille_index") * @Method("GET") * @Security("has_role('ROLE_USER')") */ public function indexAction(Request $request) { $em = $this->getDoctrine()->getManager(); $paginator = $this->get('knp_paginator'); $familles = $paginator->paginate( $em->getRepository('EEMArticleBundle:Famille')->findAll(), /* query NOT result */ $request->query->getInt('page', 1)/* page number */, 10/* limit per page */ ); return $this->render('@EEMArticle/famille/index.html.twig', array( 'familles' => $familles, )); } /** * Creates a new famille entity. * * @Route("/new", name="famille_new") * @Method({"GET", "POST"}) * @Security("has_role('ROLE_USER')") */ public function newAction(Request $request) { $famille = new Famille(); $form = $this->createForm('EEM\ArticleBundle\Form\FamilleType', $famille); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($famille); $em->flush(); $this->addFlash('success', 'Nouvelle famille ajoutée avec succès.'); return $this->redirectToRoute('famille_show', array('id' => $famille->getId())); } return $this->render('@EEMArticle/famille/new.html.twig', array( 'famille' => $famille, 'form' => $form->createView(), )); } /** * Finds and displays a famille entity. * * @Route("/{id}", name="famille_show") * @Method("GET") * @Security("has_role('ROLE_USER')") */ public function showAction(Famille $famille) { $deleteForm = $this->createDeleteForm($famille); return $this->render('@EEMArticle/famille/show.html.twig', array( 'famille' => $famille, 'delete_form' => $deleteForm->createView(), )); } /** * Displays a form to edit an existing famille entity. * * @Route("/{id}/edit", name="famille_edit") * @Method({"GET", "POST"}) * @Security("has_role('ROLE_USER')") */ public function editAction(Request $request, Famille $famille) { $deleteForm = $this->createDeleteForm($famille); $editForm = $this->createForm('EEM\ArticleBundle\Form\FamilleType', $famille); $editForm->handleRequest($request); if ($editForm->isSubmitted() && $editForm->isValid()) { $this->getDoctrine()->getManager()->flush(); $this->addFlash('success', 'Famille modifiée avec succès.'); return $this->redirectToRoute('famille_edit', array('id' => $famille->getId())); } return $this->render('@EEMArticle/famille/edit.html.twig', array( 'famille' => $famille, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Deletes a famille entity. * * @Route("/{id}/delete", name="famille_delete") * @Method("DELETE") * @Security("has_role('ROLE_USER')") */ public function deleteAction(Request $request, Famille $famille) { $form = $this->createDeleteForm($famille); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($famille); $em->flush(); $this->addFlash('success', 'Famille supprimée avec succès.'); } return $this->redirectToRoute('famille_index'); } /** * Creates a form to delete a famille entity. * * @param Famille $famille The famille entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Famille $famille) { return $this->createFormBuilder() ->setAction($this->generateUrl('famille_delete', array('id' => $famille->getId()))) ->setMethod('DELETE') ->getForm() ; } }