Advertisement
Eddz

Untitled

Sep 3rd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. namespace Application\Form;
  2.  
  3. use Zend\Form\Fieldset;
  4. use Zend\InputFilter\InputFilterProviderInterface;
  5. use Zend\ServiceManager\ServiceManager;
  6.  
  7. class UserFieldset extends Fieldset implements InputFilterProviderInterface
  8. {
  9.     protected $serviceManager;
  10.  
  11.     public function __construct(ServiceManager $serviceManager)
  12.     {
  13.         $this->serviceManager = $serviceManager;
  14.  
  15.         parent::__construct('my-fieldset');
  16.  
  17.         // Add an element
  18.         $this->add(array(
  19.             'type'    => 'Zend\Form\Element\Email',
  20.             'name'    => 'email',
  21.             'options' => array(
  22.                 'label' => 'Email'
  23.             ),
  24.             'attributes' => array(
  25.                 'required'  => 'required'
  26.             )
  27.         ));
  28.     }
  29.  
  30.     public function getInputFilterSpecification()
  31.     {
  32.         $entityManager = $this->serviceManager->get('Doctrine\ORM\EntityManager');
  33.  
  34.         return array(
  35.             'email' => array(
  36.                 'validators' => array(
  37.                     array(
  38.                         'name' => 'DoctrineModule\Validator\NoObjectExists',
  39.                         'options' => array(
  40.                             'object_manager' => $entityManager->getRepository('Application\Entity\User'),
  41.                             'fields' => 'email'
  42.                         )
  43.                     )
  44.                 )
  45.             )
  46.         );
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement