Go to the documentation of this file.00001 <?php
00002
00003 namespace Admingenerated\EtraliGinangBundle\BaseCountryController;
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\Country\NewType;
00008
00009
00010 class NewController extends BaseController
00011 {
00012 public function indexAction()
00013 {
00014
00015
00016 $Country = $this->getNewObject();
00017
00018 $form = $this->createForm($this->getNewType(), $Country);
00019
00020 return $this->render('EtraliGinangBundle:CountryNew:index.html.twig', array(
00021 "Country" => $Country,
00022 "form" => $form->createView(),
00023 ));
00024 }
00025
00026 public function createAction()
00027 {
00028
00029
00030 $Country = $this->getNewObject();
00031
00032 $form = $this->createForm($this->getNewType(), $Country);
00033 $form->bindRequest($this->get('request'));
00034
00035 if ($form->isValid()) {
00036 try {
00037 $this->preSave($form, $Country);
00038 $this->saveObject($Country);
00039 $this->postSave($form, $Country);
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_Country_new" ));
00045 if($this->get('request')->request->has('save-and-list'))
00046 return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Country_list" ));
00047 else
00048 return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Country_edit", array('pk' => $Country->getIdCountry()) ));
00049 } catch (\Exception $e) {
00050 $this->get('session')->setFlash('error', $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
00051 $this->onException($e, $form, $Country);
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:CountryNew:index.html.twig', array(
00059 "Country" => $Country,
00060 "form" => $form->createView(),
00061 ));
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071 public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Country $Country)
00072 {
00073 if ($this->container->getParameter('kernel.debug')) {
00074 throw $exception;
00075 }
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 public function preSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Country $Country)
00085 {
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 public function postSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Country $Country)
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\Country;
00110 }
00111
00112 protected function saveObject(\Etrali\GinangBundle\Entity\Country $Country)
00113 {
00114 $em = $this->getDoctrine()->getEntityManager();
00115 $em->persist($Country);
00116 $em->flush();
00117 }
00118 }