Created
July 7, 2012 21:41
-
-
Save bakura10/3068163 to your computer and use it in GitHub Desktop.
Some code that make you want to use Zend\Registry
This file contains 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
// 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