我正在使用zfcuser,bjyauthorize和roleuserbridge。 我想在表单注册中添加一个字段。我按照本教程步骤操作: http://resoftsol.com/adding-custom-fields-to-zfcuser-register-form/
在模块前面我添加了: - 具有文件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;
}
} ++++++++++++++++++++++++++ 我也添加了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
答案 0 :(得分:1)
我自己就遇到了这个问题并且能够解决它......最后。
将ZfcUser \ Validator文件夹复制到您的模块中。 调整命名空间并将方法AbstractRecord :: setMapper的预期Object类型更改为您的用户实体/接口,无论您现在拥有什么。
此外,在您提供的代码中,名称空间不相同。 Yout在那里得到了“Front”和“Font”。
编辑:忘了重要的部分xD
完成后,您需要在配置文件中使用以下代码(我的模块称为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;
},
我希望这会有所帮助。
答案 1 :(得分:0)
您不应该创建自己的界面(如果这样做,您的新界面应该扩展ZfcUser \ Entity \ UserInterface),而只是让您的用户实体扩展ZfcUser \ Entity \ UserInterface。