0

我正在使用 zfcuser、bjyauthorize 和 roleuserbridge。我想在表单注册中添加一个字段。我按照本教程步骤操作: http ://resoftsol.com/adding-custom-fields-to-zfcuser-register-form/

在模块前面我添加了: - 带有文件用户和用户界面的目录实体:

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;
   }

} ++++++++++++++++++++++++++++ 我也添加了mapp目录。我有以下错误:

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
4

2 回答 2

1

我自己也遇到了这个问题,并且能够解决它......最后。

将 ZfcUser\Validator 文件夹复制到您的模块中。调整命名空间并将 AbstractRecord::setMapper 方法的预期对象类型更改为您的用户实体/界面,无论您现在拥有什么。

此外,在您提供的代码中,命名空间并不相同。你在那里有“Front”和“Font”。

编辑:忘记了重要的部分xD

完成后,您需要配置文件中的以下代码(我的模块称为用户):

'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;
                },

我希望这有帮助。

于 2014-06-03T16:49:45.207 回答
0

你不应该创建你自己的接口(如果你这样做了,你的新接口应该扩展 ZfcUser\Entity\UserInterface),而只是让你的用户实体扩展 ZfcUser\Entity\UserInterface。

于 2014-05-25T10:15:49.670 回答