Gina Next Generation
 All Classes Namespaces Files Functions Variables
NewController.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Admingenerated\EtraliGinangBundle\BaseCivilityController;
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\Civility\NewType;
00008 
00009 
00010 class NewController extends BaseController
00011 {
00012     public function indexAction()
00013     {
00014         
00015 
00016         $Civility = $this->getNewObject();
00017 
00018         $form = $this->createForm($this->getNewType(), $Civility);
00019 
00020         return $this->render('EtraliGinangBundle:CivilityNew:index.html.twig', array(
00021             "Civility" => $Civility,
00022             "form" => $form->createView(),
00023         ));
00024     }
00025 
00026     public function createAction()
00027     {
00028         
00029 
00030         $Civility = $this->getNewObject();
00031 
00032         $form = $this->createForm($this->getNewType(), $Civility);
00033         $form->bindRequest($this->get('request'));
00034 
00035         if ($form->isValid()) {
00036             try {
00037                 $this->preSave($form, $Civility);
00038                 $this->saveObject($Civility);
00039                 $this->postSave($form, $Civility);
00040 
00041                 $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
00042            
00043                 if($this->get('request')->request->has('save-and-add'))
00044                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Civility_new" ));
00045                 if($this->get('request')->request->has('save-and-list'))
00046                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Civility_list" ));
00047                 else
00048                   return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Civility_edit", array('pk' => $Civility->getIdCivility()) ));
00049             } catch (\Exception $e) {
00050                 $this->get('session')->setFlash('error',  $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
00051                 $this->onException($e, $form, $Civility);
00052             }
00053 
00054         } else {
00055             $this->get('session')->setFlash('error', $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
00056         }
00057 
00058         return $this->render('EtraliGinangBundle:CivilityNew:index.html.twig', array(
00059             "Civility" => $Civility,
00060             "form" => $form->createView(),
00061         ));
00062     }
00063 
00064     /**
00065      * This method is here to make your life better, so overwrite it
00066      *
00067      * @param \Exception $exception throwed exception
00068      * @param \Symfony\Component\Form\Form $form the valid form
00069      * @param \Etrali\GinangBundle\Entity\Civility $Civility your \Etrali\GinangBundle\Entity\Civility object
00070      */
00071     public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Civility $Civility)
00072     {
00073         if ($this->container->getParameter('kernel.debug')) {
00074             throw $exception;
00075         }
00076     }
00077 
00078     /**
00079      * This method is here to make your life better, so overwrite  it
00080      *
00081      * @param \Symfony\Component\Form\Form $form the valid form
00082      * @param \Etrali\GinangBundle\Entity\Civility $Civility your \Etrali\GinangBundle\Entity\Civility object
00083      */
00084     public function preSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Civility $Civility)
00085     {
00086     }
00087 
00088     /**
00089      * This method is here to make your life better, so overwrite  it
00090      *
00091      * @param \Symfony\Component\Form\Form $form the valid form
00092      * @param \Etrali\GinangBundle\Entity\Civility $Civility your \Etrali\GinangBundle\Entity\Civility object
00093      */
00094     public function postSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Civility $Civility)
00095     {
00096     }
00097 
00098 
00099     protected function getNewType()
00100     {
00101         $type = new NewType();
00102         $type->setSecurityContext($this->get('security.context'));
00103 
00104         return $type;
00105     }
00106 
00107     protected function getNewObject()
00108     {
00109         return new \Etrali\GinangBundle\Entity\Civility;
00110     }
00111 
00112     protected function saveObject(\Etrali\GinangBundle\Entity\Civility $Civility)
00113     {
00114         $em = $this->getDoctrine()->getEntityManager();
00115         $em->persist($Civility);
00116         $em->flush();
00117     }
00118 }
 All Classes Namespaces Files Functions Variables