Skip to content

Instantly share code, notes, and snippets.

@juizmill
Created April 18, 2014 19:46
Show Gist options
  • Select an option

  • Save juizmill/11061286 to your computer and use it in GitHub Desktop.

Select an option

Save juizmill/11061286 to your computer and use it in GitHub Desktop.
Factory Form
<?php
/**
* WebPatterns (http://webpatterns.com.br/)
*
* @copyright Copyright (c) 2014-2014. (http://www.webpatterns.com.br)
* @license http://webpatterns.com.br/license
*/
namespace WPAcl\Form;
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
use WPAcl\Entity\Role;
use Zend\Form\Element\Button;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Class FactoryRoleForm
* @package WPAcl\Form
*/
class FactoryRoleForm implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$em = $serviceLocator->get('doctrine.entitymanager.orm_default');
$builder = new AnnotationBuilder($em);
$form = $builder->createForm(new Role());
//Role
$form->get('parent_id')->setOptions(array(
'label' => 'Tipo de Usuário',
'object_manager' => $em,
'target_class' => 'WPAcl\Entity\Role',
'empty_option' => '--Selecione--',
'property' => 'name',
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array(),
'orderBy' => array('name' => 'ASC'),
),
),
));
//Botão para enviar
$button = new Button('salvar');
$button->setLabel('Salvar')
->setAttributes(array(
'class' => 'btn btn-primary',
'type' => 'submit',
));
$form->add($button);
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment