Hello guys! 
I am a ZendFramework2 newbie and I am trying to extend the ZfcUser module. I
installed and works perfectly out of the box. What i want is to add extra
fields to the registration form and have that data saved in my MySQL
database. I followed tutorials and even Q&As from stackoverflow but I can't
get the custom field data to get saved in my database. This is what I have
so far:

I have successfully setup the configuration file for zfcuser my users (not
user) table in my database. And also use my User Entity.

\config\autoload\zfcuser.global.php

    $settings = array(
                ...
                'user_entity_class' => 'Application\Entity\User',
                'table_name' => 'users',
                ...
                )

I load my application after the ZfcUser module.

\config\applicationc.onfig.php

    return array(
        'modules' => array(
            'ZfcBase',
            'ZfcUser',
            'Application',
            ...
            )
        
My User entity implements UserInterface. It's basically a copy of the
original User entity with an extra website variable, and its setter and
getter functions.

\module\Application\src\Application\Entity\User.php

    <?php
    namespace Application\Entity;
     
    use ZfcUser\Entity\UserInterface;
    
    class User implements UserInterface
    {
        
        protected $id;
        protected $username;
        protected $email;
        protected $displayName;
        protected $password;
        protected $state;
        
        protected $website;
        
        ....
        
         public function setWebsite($website)
        {
            $this->website = $website;
            return $this;
        } 
    
        public function getWebsite($website)
        {
            $this->website = $website;
            return $this;
        }     
     }
    ...
    ?>


I managed to override zfcuser views by creating the proper phtml files in
\module\Application\view\zfcuser\user\.

And I also managed to add an extra 'website' field to the registration form
by altering the \module\Application\Module.php

    class Module 
    
    {
    ...
        public function onBootstrap(MvcEvent $e)
        {
            $eventManager        = $e->getApplication()->getEventManager();
            $moduleRouteListener = new ModuleRouteListener();
            $moduleRouteListener->attach($eventManager);
            
               
            $app = $e->getParam('application');
            // $em is a Zend\EventManager\SharedEventManager
            $em  = $app->getEventManager()->getSharedManager();
    
            $em->attach('ZfcUser\Form\Register', 'init', function($e) {
            // $form is a ZfcUser\Form\Register
            $form = $e->getTarget();
    
            $form->add(array(
                'name' => 'website',
                'options' => array(
                    'label' => 'Website',
                    ),
                'attributes' => array(
                    'type' => 'text'
                    ),
                ));
            });           
        }
     ...
     }

 
 I have a Website field in my 'users' table in my database. However the data
is not saved.
 So my question is how do i save the data from my custom form fields ?
 Any help would be very much appreciated.




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Extending-zfcuser-Having-problems-with-getting-the-custom-form-fields-data-saved-to-the-database-tp4661247.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to