Gina Next Generation
 All Classes Namespaces Files Functions Variables
EditController.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Admingenerated\EtraliGinangBundle\BaseCityController;
00004 
00005 use Admingenerator\GeneratorBundle\Controller\Doctrine\BaseController as BaseController;
00006 use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
00007 use Etrali\GinangBundle\Form\Type\City\EditType;
00008 
00009 
00010 
00011 class EditController extends BaseController
00012 {
00013     public function indexAction($pk)
00014     {
00015         $City = $this->getObject($pk);
00016 
00017         
00018 
00019         if (!$City) {
00020             throw new NotFoundHttpException("The Etrali\GinangBundle\Entity\City with idCity $pk can't be found");
00021         }
00022 
00023         $form = $this->createForm($this->getEditType(), $City);
00024 
00025         return $this->render('EtraliGinangBundle:CityEdit:index.html.twig', array(
00026             "City" => $City,
00027             "form" => $form->createView(),
00028         ));
00029     }
00030 
00031     public function updateAction($pk)
00032     {
00033         $City = $this->getObject($pk);
00034 
00035         
00036 
00037         if (!$City) {
00038             throw new NotFoundHttpException("The Etrali\GinangBundle\Entity\City with idCity $pk can't be found");
00039         }
00040 
00041         $this->preBindRequest($City);
00042         $form = $this->createForm($this->getEditType(), $City);
00043         $form->bindRequest($this->get('request'));
00044 
00045         if ($form->isValid()) {
00046             try {
00047                 $this->preSave($form, $City);
00048                 $this->saveObject($City);
00049                 $this->postSave($form, $City);
00050 
00051                 $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
00052                 
00053                 if($this->get('request')->request->has('save-and-add'))
00054                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_City_new" ));
00055                 if($this->get('request')->request->has('save-and-list'))
00056                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_City_list" ));
00057                 else
00058                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_City_edit", array('pk' => $pk) ));
00059             } catch (\Exception $e) {
00060                 $this->get('session')->setFlash('error',  $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
00061                 $this->onException($e, $form, $City);
00062             }
00063 
00064         } else {
00065             $this->get('session')->setFlash('error',  $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
00066         }
00067 
00068         return $this->render('EtraliGinangBundle:CityEdit:index.html.twig', array(
00069             "City" => $City,
00070             "form" => $form->createView(),
00071         ));
00072     }
00073 
00074     /**
00075      * This method is here to make your life better, so overwrite it
00076      *
00077      * @param \Exception $exception throwed exception
00078      * @param \Symfony\Component\Form\Form $form the valid form
00079      * @param \Etrali\GinangBundle\Entity\City $City your \Etrali\GinangBundle\Entity\City object
00080      */
00081     public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\City $City)
00082     {
00083         if ($this->container->getParameter('kernel.debug')) {
00084             throw $exception;
00085         }
00086     }
00087 
00088     /**
00089      * This method is here to make your life better, so overwrite  it
00090      *
00091      * @param \Etrali\GinangBundle\Entity\City $City your \Etrali\GinangBundle\Entity\City object
00092      */
00093     public function preBindRequest(\Etrali\GinangBundle\Entity\City $City)
00094     {
00095     }
00096 
00097     /**
00098      * This method is here to make your life better, so overwrite  it
00099      *
00100      * @param \Symfony\Component\Form\Form $form the valid form
00101      * @param \Etrali\GinangBundle\Entity\City $City your \Etrali\GinangBundle\Entity\City object
00102      */
00103     public function preSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\City $City)
00104     {
00105     }
00106 
00107     /**
00108      * This method is here to make your life better, so overwrite  it
00109      *
00110      * @param \Symfony\Component\Form\Form $form the valid form
00111      * @param \Etrali\GinangBundle\Entity\City $City your \Etrali\GinangBundle\Entity\City object
00112      */
00113     public function postSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\City $City)
00114     {
00115     }
00116 
00117 
00118     protected function getEditType()
00119     {
00120         $type = new EditType();
00121         $type->setSecurityContext($this->get('security.context'));
00122 
00123         return $type;
00124     }
00125 
00126     protected function getObject($pk)
00127     {
00128         return $this->getDoctrine()
00129                     ->getEntityManager()
00130                     ->getRepository('Etrali\GinangBundle\Entity\City')
00131                     ->find($pk);
00132     }
00133 
00134     protected function saveObject(\Etrali\GinangBundle\Entity\City $City)
00135     {
00136         $em = $this->getDoctrine()->getEntityManager();
00137         $em->persist($City);
00138         $em->flush();
00139     }
00140 }
 All Classes Namespaces Files Functions Variables