Created
July 26, 2012 14:26
-
-
Save manuakasam/3182357 to your computer and use it in GitHub Desktop.
Create Doctrine based Form via Factory with Collections and Select Elements Hydratable
This file contains 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
<?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