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; | |
} | |
} |
namespace cwdAdmin\Service; | |
use cwdCommon\Service; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
use Zend\ServiceManager\ServiceLocatorAwareInterface; | |
/** | |
* ServiceFactory | |
* | |
* @category cwdAdmin | |
* @package CWD | |
* @subpackage Service | |
**/ | |
class ServiceFactory implements ServiceLocatorAwareInterface | |
{ | |
/** | |
* @var \Zend\ServiceManager\ServiceLocatorInterface | |
*/ | |
protected $serviceLocator; | |
public function setUp(Service $object) | |
{ | |
$object->setServiceLocator($this->getServiceLocator()); | |
$object->setLogger($this->getServiceLocator()->get('Logger')); | |
$form = $object->getFormClass(); | |
$entity = $object->getEntityClass(); | |
$form->setServiceLocator($this->getServiceLocator()); | |
if($form instanceof InputFilterAwareInterface) { | |
$form->setInputFilter($entity->getInputFilter()); | |
} | |
$form->changeViewHelper(); | |
$form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods()); | |
$object->setEntity($entity); | |
$object->setForm($form); | |
return $object; | |
} | |
/* (non-PHPdoc) | |
* @see \Zend\ServiceManager\ServiceLocatorAwareInterface::getServiceLocator() | |
*/ | |
public function getServiceLocator() | |
{ | |
return $this->serviceLocator; | |
} | |
/* (non-PHPdoc) | |
* @see \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator() | |
*/ | |
public function setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) | |
{ | |
$this->serviceLocator = $serviceLocator; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment