After a couple of days of learning ZF2 I finally got somewhere with extending
the ZfcUser class to add custom fields. I used the customizable
user_entity_class definition in the zfc.global.php to specify a new class
"myUser" that extends \ZfcUser\Entity\User.  It took me a while to realize
that you need the leading forward slash on Hard coded class references, like
when you are extending classes,  but not on dynamic class references that
are stored in variables like the user_entity_class variable. Hello PHP
namespace! I feel like that was a few wasted hours.  

I am not 100% clear why the leading slash matters for dynamic vs hard coded
namespaces but it makes snes for relative vs fully qualified name spaces. 
like this code for the factory definition in my module.php has the local
namespaced copies of the Form\registerForm without the leading forward slash
but for the fully qualified namespaced validators they have the leading
slash like \ZfcUser\Validator\NoRecordExists.  It was trial and error to get
it all working.

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



So I have successfully had myUser extended ZfcUser; added my custom fields
to myUser; created the custom getters and setters which is the key to the
mapper functions extracting all the data to the array that gets used in the
SQL query.   Thus I am finally able to get data into the database correctly. 
Hopefully that will help anyone that stumbles across this and is looking for
a little insight on what to do.

But now my question is am I extending ZfcUser in the most efficient way.  I
have extended the user class and then I extended the registration form to
add my new fields this form.  I had to add some data mappers for loading
drop down values in my extended registration form.  Once I added more fields
then I also had to extend the registrationFilter class to add the validation
for my new fields.  Then In order to instantiate these items I overrode the
serviceLocator factory entries in my Module.php file so that the calls to
zfcuser_registration_form loads my form rather than the original form. I
just feel like there are a lot of extra levels of abstraction that are going
to be very confusing to figure it all out when I stop looking at for a year
and have to make changes.  It almost seems like with the level of extending
I did it was almost better to fork zfcuser as my own module and just modify
the core as needed forgoing the upgrade possibilities in the future.

Anyone have any thoughts on this?  I realize it should be a separate
question but I just wanted get any feedback on a better way to extend
ZfcUser without feeling like I am rewriting everything in my own classes
anyway. It just feels like modifying the zfcuser classes with my custom code
might be the easier approach after all.  I am still trying to learn the
details of the ZF2 framework so I am probably misguided.  I used ZF1 a lot
and I loved it. I remember the steep learning curve back then but I feel
like going from ZF1 to ZF2 introduces the same steep learning curve all over
again.  As a reult I am sure I am making a lot of mistake or points that
could be more refined.  So if anyone has any insight please share.  I have
tried search the web for days now and a lot of the documentation is sparse
or applies to old versions of the ZF2 that are not even recommend to use
anymore. Any direction is welcome. 



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZfcUser-customizing-fields-tp4659153p4659218.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to