Example #1
0
 private function getWidgetEdit()
 {
     /*$id = $this->params()->fromRoute('id');
     		if (!$id) return $this->redirect()->toRoute('inventory', array('controller' => 'inventory', 'action' => 'index'));*/
     try {
         $repository = $this->em->getRepository($this->getMyEntity());
         $record = $repository->find($this->id);
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         // this never will be seen fi you don't comment the redirect
         //return $this->redirect()->toRoute('inventory', array('controller' => 'inventory', 'action' => 'index'));
     }
     //$this->layout()->setVariable('exampleH1', $article->getName());
     $widgetForm = new WidgetForm();
     $form = $widgetForm->getForm($record, $this->em, $this->getMyEntity(), 'Сохранить');
     $form->bind($record);
     //$request = $this->getRequest();
     //if ($request->isPost()) {
     if ($this->getPost() !== null) {
         //$post = $request->getPost();
         $post = $this->getPost();
         // uncooment and fix if you want to control the date and time
         //			$post->artcCreated = $post->artcCreatedDate . ' ' . $post->artcCreatedTime;
         $form->setData($post);
         if ($form->isValid()) {
             //				$this->prepareData($article);
             $this->em->persist($record);
             $this->em->flush();
             //return $this->redirect()->toRoute($this->getController(), array('controller' => $this->getController(), 'action' => 'index', 'id' => $this->id));
             $redirect = 'index';
         }
     }
     return array('form' => $form, 'redirect' => $redirect);
 }