0

In my database I have the tables : "clients", "userProfile", and "sfGuardUsers"

I want the system to create a profile and a user when I create a new client. Here's what I have so far :

in lib/form/doctrine/ClientForm.class.php :

class ClientForm extends BaseClientForm
{
  public function configure()
  {
    parent::configure();

    $userProfileForm = new UserProfileForm($this->object->UserProfile->user);
    $this->mergeForm($userProfileForm);
  }
}

in modules/client/action/actions.class.php :

class clientActions extends autoClientActions
{
  public function executeCreate(sfWebRequest $request)
  {
    parent::executeCreate($request);
    $this->client->createProfile($request->getParameter('email'),$request->getParameter('password'));
  }

in lib/model/doctrine/Client.class.php :

  public function createProfile($email, $password)
  {
    $profil = Doctrine_Core::getTable('UserProfile')->findOneByClientId($this->getId());
    $profil->createUser($email, $password);
    $profil->setClient($this);
    $profil->save();
  }

According to the log, createProfile(null, null) is called, and mysql creates a user with '' as its username :(

Manu
  • 4,410
  • 6
  • 43
  • 77

1 Answers1

2

You don't need to do that. Check the readme file. You need this in app.yml:

sf_guard_plugin:
  profile_class:      sfGuardUserProfile
  profile_field_name: user_id

And, of course, in your db schema, when defining the profile table, you need to also define its relation with sf_guard_user table.

The plugin will do the rest for you (adding/saving the new profile when need).

Vlad Jula-Nedelcu
  • 1,681
  • 11
  • 17
  • The thing is, my users can either be "clients" or "suppliers', so all I have in the profile class is client_id and supplier_id. So when I add a client I have to save it, then the profile, then the sfuser – Manu Feb 16 '12 at 14:34
  • how do you decide if it's a supplier or a client? Different forms? Then you can override the form save/doSave/updateObject method (depends on your situation) and to something like `$this->getObject()->getProfile()->setType('client')` – Vlad Jula-Nedelcu Feb 16 '12 at 15:45
  • yes admins will have one form to create suppliers, another to create clients. Both should the create the profile, the sfUser, and link everyone together. – Manu Feb 16 '12 at 15:57