Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
currently
public function createAction()
{
$service = $this->getService();
$form = $service->getForm();
$entity = $service->getEntity();
$form->bind($entity);
if($this->request->isPost()) {
$mandator = $this->getEntityManager()->find('Admin\Entity\Mandator', $_POST['mandator_id']); //<--- should not be needed
$_POST['mandator'] = $mandator;
$form->setData($this->request->getPost());
$this->getLogger()->info('Form Post', $_POST);
if($form->isValid()) {
$entity->setMandator($mandator); //<-- should not be needed
$service->persist($entity);
$this->getLogger()->info($entity->getName().' Successfully saved');
$this->getMessenger()->setNamespace('ok')->addMessage('%s successfully saved');
$this->redirect()->toUrl('/agency/list');
}
}
return new ViewModel(array('form' => $form));
}
<?php
namespace Admin\Form;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\Form\Element\Select;
use cwdAdmin\Form\DisplayGroup;
use cwdAdmin\Form\Form;
class Agency extends Form implements InputFilterAwareInterface {
public function invoke()
{
parent::__construct('agency');
$this->setAttribute('method', 'post');
$this->addHidden('agency_id');
$this->addText('name', 'Name', true);
$this->addText('address', 'Address');
$this->addText('address2', 'Address2');
$this->addText('zipcode', 'Zipcode');
$this->addText('city', 'City');
$this->addText('uid', 'UID');
$select = new Select('country');
$select->setAttribute('type', 'select')
->setValueOptions($this->countryOptions())
->setLabel('Country');
$this->add($select);
$address = new DisplayGroup('fs_address', 'Address');
$address->add('name')
->add('address')
->add('address2')
->add('zipcode')
->add('city')
->add('country')
->add('uid');
$this->addDisplayGroup($address);
$this->addText('phone', 'Phone');
$this->addText('fax', 'Fax');
$this->addText('url', 'URL');
$this->addText('email', 'EMail');
$contact = new DisplayGroup('fs_contact', 'Contact');
$contact->add('phone')
->add('fax')
->add('url')
->add('email');
$this->addDisplayGroup($contact);
$select = new Select('mandator_id');
$select->setAttribute('type', 'select')
->setValueOptions($this->getMandator())
->setLabel('Mandator');
$this->add($select);
$admin = new DisplayGroup('fs_admin', 'Administration');
$admin->add('mandator_id');
$this->addDisplayGroup($admin);
}
public function getMandator() {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$rep = $em->getRepository('Admin\Entity\Mandator');
$rows = $rep->findBy(array());
$data = array();
foreach($rows as $row) {
$data[$row->getMandatorId()] = $row->getName();
}
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.