Created
April 18, 2014 19:46
-
-
Save juizmill/11061286 to your computer and use it in GitHub Desktop.
Factory Form
This file contains hidden or 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 | |
| /** | |
| * 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