在 sfDoctrineGuardPlugin 中设置用户名等于 email_address

发布于 2024-10-30 18:13:42 字数 395 浏览 0 评论 0原文

在表sf_guard_user中,需要email_addressusername,但我想使用电子邮件作为username

所以,我正在考虑从表单中删除此字段之一,但由于需要,我总是收到错误,并且我正在尝试设置 username = email_address 或反之亦然,我在操作、表单和模型中尝试过,但没有成功......

认为在 sfGuardUser 模型中编写一个名为 getUsername( ) 并返回电子邮件就足够了,但是不行……

这可能吗? 我该怎么办?

谢谢

in the table sf_guard_user, the email_address and username are requiered, but i want to use the email as username

so, i'm thinking to remove one of this field from the form, but as it are required, i always get the error, and i'm trying to set the username = email_address or vice versa, i've tried in the action, form, and model, but no success....

thought that writing a function in the sfGuardUser model with the name getUsername() and returning the email was enough, but no........

is this possible??
how can i do it??

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终 2024-11-06 18:13:42

当然这是可能的。您甚至不必搞乱架构。只需将电子邮件存储在用户名和电子邮件地址中即可。

class sfGuardUserForm extends PluginsfGuardUserForm
{
  public function doSave($con = null)
  {
    //update object with form values
    $this->updateObject();
    $this->getObject()->setUsername($this->getObject()->getEmailAddress());

    return parent::doSave($con);
  }
}

Of cause it is possible. You don't even have to mess with schema. Just store email in both username and email_address.

class sfGuardUserForm extends PluginsfGuardUserForm
{
  public function doSave($con = null)
  {
    //update object with form values
    $this->updateObject();
    $this->getObject()->setUsername($this->getObject()->getEmailAddress());

    return parent::doSave($con);
  }
}
美男兮 2024-11-06 18:13:42

覆盖 Object::save() 函数中的用户名字段是更好的方法 - 以便它处理所有表单。

在您的表单中,您可以覆盖用户名小部件的验证器。如果需要,您还可以隐藏该小部件。

class sfGuardUserAdminForm extends BasesfGuardUserAdminForm
{

  public function setup()
  {
    parent::setup();
    $this->setWidget('username', new sfWidgetFormInputHidden());
    $this->setValidator('username', new sfValidatorPass());
  }

}

class sfGuardUser extends PluginsfGuardUser
{
  public function save(Doctrine_Connection $conn = null){
    $this->setUsername($this->getEmailAddress());
    parent::save($conn);
  }
}

Overriding username field in the Object::save() function is much better way - so that it handles all forms.

In you forms, you override the validator for username widget. You can also hide the widget if you want.

class sfGuardUserAdminForm extends BasesfGuardUserAdminForm
{

  public function setup()
  {
    parent::setup();
    $this->setWidget('username', new sfWidgetFormInputHidden());
    $this->setValidator('username', new sfValidatorPass());
  }

}

and

class sfGuardUser extends PluginsfGuardUser
{
  public function save(Doctrine_Connection $conn = null){
    $this->setUsername($this->getEmailAddress());
    parent::save($conn);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文