Created
December 30, 2012 20:21
-
-
Save manuakasam/4414902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function editAction() | |
| { | |
| $vm = new ViewModel(); | |
| $vm->setTemplate('haushaltportal/ergebnishaushalt/edit.phtml'); | |
| /** | |
| * Service-Manager ansprechen um Objekte zu erhalten | |
| * | |
| * @var $form \Haushaltportal\Form\ErgebnishaushaltProduktForm | |
| * @var $entityService \Haushaltportal\Service\ErgebnishaushaltProduktService | |
| */ | |
| $form = $this->getServiceLocator()->get('ergebnishaushalt-form-produkt'); | |
| $entityService = $this->getServiceLocator()->get('ergebnishaushalt-service-produkt'); | |
| $request = $this->getRequest(); | |
| $id = $this->params('id'); | |
| $entity = $entityService->find($id); | |
| $form->bind($entity); | |
| //\Zend\Debug\Debug::dump($form->getObject()); | |
| if ($request->isPost()) { | |
| $form->setData($request->getPost()); | |
| if ($form->isValid()) { | |
| try { | |
| $entityService->persist($entity); | |
| $vm->setVariable('message', 'Erfolgreich bearbeitet!'); | |
| } catch (\Exception $e) { | |
| $form->setMessages(array( | |
| 'submit' => array('Datenbankfehler. Folgende Nachricht wurde ausgegeben: ' . $e->getMessage()) | |
| )); | |
| } | |
| } | |
| } | |
| return $vm->setVariable('form', $form); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function __construct($name, $options = array()) | |
| { | |
| parent::__construct($name, $options); | |
| $this->add(array( | |
| 'name' => 'id', | |
| 'attributes' => array( | |
| 'type' => 'hidden' | |
| ) | |
| )); | |
| $this->add(new \Zend\Form\Element\Csrf('awesomesecurity')); | |
| $this->add(array( | |
| 'name' => 'produktBereich', | |
| 'type' => 'DoctrineModule\Form\Element\ObjectSelect', | |
| 'attributes' => array( | |
| 'required' => true | |
| ), | |
| 'options' => array( | |
| 'label' => 'Produktbereich', | |
| 'empty_option' => '--- Produktbereich auswählen ---', | |
| 'object_manager' => $this->getEntityManager(), | |
| 'target_class' => 'Haushaltportal\Entity\Produktbereich', | |
| 'label_generator' => function ($targetEntity) { | |
| return $targetEntity->getNummer() . ' - ' . $targetEntity->getTitelOriginal(); | |
| } | |
| ) | |
| )); | |