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

Symfony1 保存另一个对象时创建一个对象,symfony1,symfony-1.4,sfguard,sfdoctrineguard,Symfony1,Symfony 1.4,Sfguard,Sfdoctrineguard,在我的数据库中有表:“clients”、“userProfile”和“sfGuardUsers” 我希望系统在创建新客户端时创建配置文件和用户。以下是我目前掌握的情况: 在lib/form/doctrine/ClientForm.class.php中: 在modules/client/action/actions.class.php中: 在lib/model/doctrine/Client.class.php中: 根据日志,调用了createProfile(null,null),mysql创建了

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

我希望系统在创建新客户端时创建配置文件和用户。以下是我目前掌握的情况:

在lib/form/doctrine/ClientForm.class.php中:

在modules/client/action/actions.class.php中:

在lib/model/doctrine/Client.class.php中:


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

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

sf_guard_plugin:
  profile_class:      sfGuardUserProfile
  profile_field_name: user_id
当然,在db模式中,在定义概要文件表时,还需要定义它与
sf\u guard\u user table
的关系


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

问题是,我的用户可以是“客户端”或“suppliers”,所以我在profile类中只有client_id和supplier_id。因此,当我添加一个客户端时,我必须保存它,然后是profile,然后是SFUsers。您如何确定它是供应商还是客户端?不同的表单?然后您可以覆盖表单save/doSave/updateObject方法(取决于您的情况)对于类似
$this->getObject()->getProfile()->setType('client')
是的,管理员将有一个表单来创建供应商,另一个表单来创建客户机。两者都应该创建配置文件、sfUser,并将所有人链接在一起。
class clientActions extends autoClientActions
{
  public function executeCreate(sfWebRequest $request)
  {
    parent::executeCreate($request);
    $this->client->createProfile($request->getParameter('email'),$request->getParameter('password'));
  }
  public function createProfile($email, $password)
  {
    $profil = Doctrine_Core::getTable('UserProfile')->findOneByClientId($this->getId());
    $profil->createUser($email, $password);
    $profil->setClient($this);
    $profil->save();
  }
sf_guard_plugin:
  profile_class:      sfGuardUserProfile
  profile_field_name: user_id