保存另一个时创建一个对象

时间:2012-02-16 14:15:07

标签: symfony1 symfony-1.4 sfguard sfdoctrineguard

在我的数据库中,我有表:“clients”“userProfile”“sfGuardUsers”

我希望系统在创建新客户端时创建配置文件和用户。这是我到目前为止所做的:

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);
  }
}
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'));
  }
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();
  }

根据日志调用createProfile(null, null),mysql创建一个用户名为''的用户:(

1 个答案:

答案 0 :(得分:2)

你不需要这样做。检查自述文件。 您需要app.yml

sf_guard_plugin:
  profile_class:      sfGuardUserProfile
  profile_field_name: user_id

当然,在db模式中,定义配置文件表时,还需要定义与sf_guard_user table的关系。

该插件将为您完成剩余的工作(在需要时添加/保存新的配置文件)。