Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created July 7, 2012 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakura10/3068163 to your computer and use it in GitHub Desktop.
Save bakura10/3068163 to your computer and use it in GitHub Desktop.
Some code that make you want to use Zend\Registry
// FIRST :
class Register extends Form
{
/**
* Init the form
*/
public function init()
{
$this->setHydrator(new ClassMethodsHydrator())
->setInputFilter(new InputFilter());
$this->add(array(
'type' => 'Member\Form\Type\Student',
'options' => array(
'use_as_base_fieldset' => true
)
));
}
}
// WHERE MEMBER\FORM\TYPE\STUDENT :
class Student extends AbstractUser
{
public function __construct()
{
parent::__construct('student');
$this->setHydrator(new ClassMethodsHydrator())
->setObject(new StudentEntity());
$this->add(array(
'type' => 'Member\Form\Type\StudentProfile'
));
}
}
// WHERE MEMBER\FORM\TYPE\ABSTRACTUSER IS :
class AbstractUser extends Fieldset implements InputFilterProviderInterface
{
/**
* Constructor
*/
public function __construct($name)
{
parent::__construct($name);
// LOTS OF ELEMENTS
$this->add(array(
'type' => 'Zend\Form\Element\Email',
'name' => 'email',
'options' => array(
'label' => 'Adresse e-mail'
),
'attributes' => array(
'required' => 'required',
'maxlength' => 128
)
));
}
/**
* @return array
*/
public function getInputFilterSpecification()
{
return array(
//
//
// NOOO NEEED SM HEREE TO GET ENTITY MANAGER :(...
//
//
'email' => array_merge_recursive(
$this->elements['email']->getInputSpecification(),
array(
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'max' => 128,
'encoding' => 'utf-8'
)
),
/*array(
'name' => 'DoctrineModule\Validation\NoEntityExists',
'options' => array(
'em' => $this->getEntityManager(),
'entity' => 'Member\Entity\AbstractUser',
'property' => 'email'
)
)*/
)
))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment