public function createService(ServiceLocatorInterface $serviceLocator) { $em = $serviceLocator->get('Doctrine\\ORM\\EntityManager'); $form = new ProjectForm($em); // $form->setInputFilter(new ProjectFilter()); $hydrator = new DoctrineHydrator($em); $nullStrategy = new NullStrategy(); $hydrator->addStrategy('estimatedHours', $nullStrategy); $hydrator->addStrategy('actualHours', $nullStrategy); $hydrator->addStrategy('estimatedCost', $nullStrategy); $hydrator->addStrategy('actualCost', $nullStrategy); $form->setHydrator($hydrator); return $form; }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); // If an id is not provided, redirecting to add action if (!$id) { return $this->redirect()->toRoute('project', array('action' => 'add')); } // Get the Project with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $project = $this->getProjectTable()->getProject($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('project', array('action' => 'index')); } $form = new ProjectForm(); $form->bind($project); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($project->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getProjectTable()->saveProject($project); // Redirect to list of projects return $this->redirect()->toRoute('project'); } } return array('id' => $id, 'form' => $form); }