KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
EDIT : My main question has now become 'How do I get the ServiceManager with the doctrine entity manager into the hands of my form, element, and input classes in some clean way?' Read on to see the full post. I'm going to try and ask by example here so bear with me. Let me know where I'm going wrong/right or where I could improve I'm trying to create a registration form. I could use ZfcUser module but I want to do this on my own. I'm using ZF2 with Doctrine2 as well so that leads me away from that module a bit. My strategy was this, Create a form class called registration form Create separate 'element' classes for each element where each element will have an input specification Since each element is a separate class from the form I can unit test each one separately. All seemed fine until I wanted to add a validator to my username element that would check that the username is NOT is use yet. Here is the code thus far namepsace My\Form; use Zend\Form\Form, Zend\Form\Element, Zend\InputFilter\Input, Zend\InputFilter\InputFilter, /** * Class name : Registration */ class Registration extends Form { const USERNAME = 'username'; const EMAIL = 'email'; const PASSWORD = 'password'; const PASS_CONFIRM = 'passwordConfirm'; const GENDER = 'gender'; const CAPTCHA = 'captcha'; const CSRF = 'csrf'; const SUBMIT = 'submit'; private $captcha = 'dumb'; public function prepareForm() { $this->setName( 'registration' ); $this->setAttributes( array( 'method' => 'post' ) ); $this->add( array( 'name' => self::USERNAME, 'type' => '\My\Form\Element\UsernameElement', 'attributes' => array( 'label' => 'Username', 'aut
Tags (comma-separated)
Save Edits
Cancel