Skip to content

Instantly share code, notes, and snippets.

@manuakasam
Created July 26, 2012 14:26
Show Gist options
  • Save manuakasam/3182357 to your computer and use it in GitHub Desktop.
Save manuakasam/3182357 to your computer and use it in GitHub Desktop.
Create Doctrine based Form via Factory with Collections and Select Elements Hydratable
<?php
namespace Zebreco\Form;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zebreco\Entity\Ticket;
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity as ClassMethods;
class TicketCreateFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$form = new TicketCreate();
$departments = $serviceLocator->get('Zebreco\Service\Department')->getDepartments();
$form->get('ticket')->get('department')->setAttribute('options', $departments);
//hydrators
$em = $serviceLocator->get('doctrine.entitymanager.orm_default');
$form->setHydrator(new ClassMethods($em));
$form->get('ticket')->setHydrator(new ClassMethods($em));
$form->get('ticket')->get('contact')->setHydrator(new ClassMethods($em));
$postFieldset = new \Zebreco\Form\Fieldset\TicketPostFieldset();
$postFieldset->setHydrator(new ClassMethods($em));
$form->get('ticket')->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'posts',
'options' => array(
'target_element' => $postFieldset
)
));
$form->bind(new Ticket());
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment