0
votes

i am using zfcuser, bjyauthorize et roleuserbridge. i want to add a field in the form registration. I followed this tutorial step : http://resoftsol.com/adding-custom-fields-to-zfcuser-register-form/

in the module front i have added : - the directory entity with files user et userinterface:

namespace Front\Entity;

interface UserInterface
{
/**
 * Get id.
 *
 * @return int
 */
public function getId();

/**
 * Set id.
 *
 * @param int $id
 * @return UserInterface
 */
public function setId($id);

/**
 * Get username.
 *
 * @return string
 */
public function getUsername();

/**
 * Set username.
 *
 * @param string $username
 * @return UserInterface
 */
public function setUsername($username);

/**
 * Get email.
 *
 * @return string
 */
public function getEmail();

/**
 * Set email.
 *
 * @param string $email
 * @return UserInterface
 */
public function setEmail($email);

/**
 * Get displayName.
 *
 * @return string
 */
public function getDisplayName();

/**
 * Set displayName.
 *
 * @param string $displayName
 * @return UserInterface
 */
public function setDisplayName($displayName);

/**
 * Get password.
 *
 * @return string password
 */
public function getPassword();

/**
 * Set password.
 *
 * @param string $password
 * @return UserInterface
 */
public function setPassword($password);

/**
 * Get state.
 *
 * @return int
 */
public function getState();

/**
 * Set state.
 *
 * @param int $state
 * @return UserInterface
 */
public function setState($state);

/**
 * Get role.
 *
 * @return string
 */
public function getRole();

/**
 * Set role.
 *
 * @param string $role
 * @return UserInterface
 */
public function setRole($role);

}

++++++++++++++++++++

namespace Font\Entity;

class User implements UserInterface 
{
/**
 * @var int
 */
protected $id;

/**
 * @var string
 */
protected $username;

/**
 * @var string
 */
protected $email;

/**
 * @var string
 */
protected $displayName;

/**
 * @var string
 */
protected $password;

/**
 * @var int
 */
protected $state;


/**
 * @var string
 */
protected $role;

/**
 * Get id.
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set id.
 *
 * @param int $id
 * @return UserInterface
 */
public function setId($id)
{
    $this->id = (int) $id;
    return $this;
}

/**
 * Get username.
 *
 * @return string
 */
public function getUsername()
{
    return $this->username;
}

/**
 * Set username.
 *
 * @param string $username
 * @return UserInterface
 */
public function setUsername($username)
{
    $this->username = $username;
    return $this;
}

/**
 * Get email.
 *
 * @return string
 */
public function getEmail()
{
    return $this->email;
}

/**
 * Set email.
 *
 * @param string $email
 * @return UserInterface
 */
public function setEmail($email)
{
    $this->email = $email;
    return $this;
}

/**
 * Get displayName.
 *
 * @return string
 */
public function getDisplayName()
{
    return $this->displayName;
}

/**
 * Set displayName.
 *
 * @param string $displayName
 * @return UserInterface
 */
public function setDisplayName($displayName)
{
    $this->displayName = $displayName;
    return $this;
}

/**
 * Get password.
 *
 * @return string
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set password.
 *
 * @param string $password
 * @return UserInterface
 */
public function setPassword($password)
{
    $this->password = $password;
    return $this;
}

/**
 * Get state.
 *
 * @return int
 */
public function getState()
{
    return $this->state;
}

/**
 * Set state.
 *
 * @param int $state
 * @return UserInterface
 */
public function setState($state)
{
    $this->state = $state;
    return $this;
}


/**
 * Get role.
 *
 * @return string
 */
public function getRole()
{
    return $this->role;
}

/**
 * Set role.
 *
 * @param string $role
 * @return UserInterface
 */
public function setRole($role)
{
    $this->role = $role;
    return $this;
   }

} ++++++++++++++++++++++++++ also i have add the mapp directory. i had the following error :

Catchable fatal error: Argument 1 passed to ZfcUser\Validator\AbstractRecord::setMapper() 
must be an instance of ZfcUser\Mapper\UserInterface, instance of Front\Mapper\User given, 
called in C:\wamppp\www\projet\vendor\zendframework\zendframework\library\Zend\Validator
\AbstractValidator.php on line 139 and defined in C:\wamppp\www\projet\vendor\zf-commons
\zfc-user\src\ZfcUser\Validator\AbstractRecord.php on line 65
2
That's a lot of code. Can you strip it down to a minimal example?user3553031

2 Answers

1
votes

I just had the problem myself and was able to solve it... finally.

Copy the ZfcUser\Validator folder into your module. Adapt the namespace and change the expected Object type of the method AbstractRecord::setMapper to your user entity / interface, whatever you have there now.

Also, in the code you provided the namespaces arent identical. Yout got "Front" and "Font" there.

Edit: forgot the important part xD

After you have done that you need the following code in the config file (my module is called User):

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

I hope this helps.

0
votes

You should not create your own interface(and if you do, your new interface should extend ZfcUser\Entity\UserInterface), instead just make your user entity extend the ZfcUser\Entity\UserInterface.