Go to the documentation of this file.00001 <?php
00002
00003 namespace Admingenerated\EtraliGinangBundle\BaseProtocolController;
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\Protocol\EditType;
00008
00009
00010
00011 class EditController extends BaseController
00012 {
00013 public function indexAction($pk)
00014 {
00015 $Protocol = $this->getObject($pk);
00016
00017
00018
00019 if (!$Protocol) {
00020 throw new NotFoundHttpException("The Etrali\GinangBundle\Entity\Protocol with idProtocol $pk can't be found");
00021 }
00022
00023 $form = $this->createForm($this->getEditType(), $Protocol);
00024
00025 return $this->render('EtraliGinangBundle:ProtocolEdit:index.html.twig', array(
00026 "Protocol" => $Protocol,
00027 "form" => $form->createView(),
00028 ));
00029 }
00030
00031 public function updateAction($pk)
00032 {
00033 $Protocol = $this->getObject($pk);
00034
00035
00036
00037 if (!$Protocol) {
00038 throw new NotFoundHttpException("The Etrali\GinangBundle\Entity\Protocol with idProtocol $pk can't be found");
00039 }
00040
00041 $this->preBindRequest($Protocol);
00042 $form = $this->createForm($this->getEditType(), $Protocol);
00043 $form->bindRequest($this->get('request'));
00044
00045 if ($form->isValid()) {
00046 try {
00047 $this->preSave($form, $Protocol);
00048 $this->saveObject($Protocol);
00049 $this->postSave($form, $Protocol);
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_Protocol_new" ));
00055 if($this->get('request')->request->has('save-and-list'))
00056 return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Protocol_list" ));
00057 else
00058 return new RedirectResponse($this->generateUrl("Etrali_GinangBundle_Protocol_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, $Protocol);
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:ProtocolEdit:index.html.twig', array(
00069 "Protocol" => $Protocol,
00070 "form" => $form->createView(),
00071 ));
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081 public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Protocol $Protocol)
00082 {
00083 if ($this->container->getParameter('kernel.debug')) {
00084 throw $exception;
00085 }
00086 }
00087
00088
00089
00090
00091
00092
00093 public function preBindRequest(\Etrali\GinangBundle\Entity\Protocol $Protocol)
00094 {
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 public function preSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Protocol $Protocol)
00104 {
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 public function postSave(\Symfony\Component\Form\Form $form, \Etrali\GinangBundle\Entity\Protocol $Protocol)
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\Protocol')
00131 ->find($pk);
00132 }
00133
00134 protected function saveObject(\Etrali\GinangBundle\Entity\Protocol $Protocol)
00135 {
00136 $em = $this->getDoctrine()->getEntityManager();
00137 $em->persist($Protocol);
00138 $em->flush();
00139 }
00140 }