Skip to content

Instantly share code, notes, and snippets.

@juizmill
Last active August 29, 2015 13:57
Show Gist options
  • Save juizmill/9443065 to your computer and use it in GitHub Desktop.
Save juizmill/9443065 to your computer and use it in GitHub Desktop.
getFormElementConfig com DOCTRINE FORM ELEMENT
public function getFormElementConfig()
{
return array(
'factories' => array(
'user.form' => function($sm){
$em = $sm->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$builder = new AnnotationBuilder();
$form = $builder->createForm('User\Entity\User');
$form->getInputFilter()->get('email')->getValidatorChain()->attach(new NoObjectExists(array(
'object_repository' => $em->getRepository('User\Entity\User'),
'fields' => array('email'),
)));
$form->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'type_user',
'options' => array(
'label' => 'Tipo de usuário',
'object_manager' => $em,
'target_class' => 'User\Entity\TypeUser',
'empty_option' => '--Selecione--',
'property' => 'name',
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array(),
'orderBy' => array('name' => 'ASC'),
),
),
),
'attributes' => array('required' => 'required')
));
$form->add(array(
'name' => 'salval',
'type' => 'Zend\Form\Element\Submit',
'attributes' => array(
'value' => 'Salvar',
'class' => 'btn btn-success btn-large',
)
));
return $form;
},
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment