0
votes

I am using Zendframework 2 with ZfcUser and ZfcUserDoctrineORM. I extended the normal user with some additional information.

Now i want to adapt the registerForm. Therefor i created this form in the ZfcUser\Form folder:

class UserRegister extends ZfcUser\Form\Register {
  public function init(){
    $this->add(array(
        'name' => 'firstName',
        'options' => array(
            'label' => 'First Name',
        ),
        'attributes' => array(
            'type' => 'text'
        ),
    ));

    $this->add(array(
        'name' => 'name',
        'options' => array(
            'label' => 'Last Name',
        ),
        'attributes' => array(
            'type' => 'text'
        ),
    ));
  }
}

In the Next step I changed adapted the getServiceConfig() function in the Module.php in the ZfcUser folder:

'zfcuser_register_form' => function ($sm) {
                $options = $sm->get('zfcuser_module_options');
                $form = new Form\UserRegister(null, $options);
                //$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
                $form->setInputFilter(new Form\RegisterFilter(
                    new Validator\NoRecordExists(array(
                        'mapper' => $sm->get('zfcuser_user_mapper'),
                        'key'    => 'email'
                    )),
                    new Validator\NoRecordExists(array(
                        'mapper' => $sm->get('zfcuser_user_mapper'),
                        'key'    => 'username'
                    )),
                    $options
                ));
                return $form;
            },

When calling the register url this error message is shown:

Fatal error: Cannot redeclare class UserRegister in C:\xampp\htdocs\THWDiver\vendor\zf-commons\zfc-user\src\ZfcUser\Form\UserRegister.php on line 24

What am I making wrong?

2
Could you show the complete code of the UserRegister.php ? It seems that there is something missing (the namespace). Also, it is not recommended that you put code into the ZfcUser module itself. It is easily possible to extend code from the ZfcUser module, and use that code instead of editing the code of ZfcUser and thereby making upgrades a lot harder.kokx
Thanks for your help. I fixed the "use" part of the file. How can i extend the ZfcUser module?Iceman
I think that would be worth a separate question.kokx
As a side note, It is not recommended at all to modify the zfcuser 's base code, rather you could override the service factory named "zfcuser_register_form" in your own module.TheFuquan

2 Answers

0
votes

Realize this is an old question, but just stumbled onto it. You need to edit your Entity module's bootstrap and attach to 'ZfcUser\Form\Register' at 'init'.

I've got a blog article here that details the solution in depth: http://circlical.com/blog/2013/4/1/l5wftnf3p7oks5561bohmb9vkpasp6

Hope it helps you!

0
votes

I think that the answer is to override the service factory "zfcuser_register_form" and inside of it declare your own RegisterForm.