Search code examples
phpsymfony1sfguard

set username equal to email_address in sfDoctrineGuardPlugin


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


Solution

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