symfony sfGuard“sfGuardUserProfile”上的未知记录属性/相关组件“sf_guard_user”

时间:2010-09-07 18:24:14

标签: symfony1

当我尝试实现此代码时,我收到此错误。带有$ user的第一个代码块似乎在数据库更新时起作用,但第二个部分失败了。这是错误:

“sfGuardUserProfile”上的未知记录属性/相关组件“sf_guard_user”

public function executeCreateAccount()
  {
    $user = new sfGuardUser();
    $user->setUsername($this->getRequestParameter('username'));
    $user->setPassword($this->getRequestParameter('password'));
    $user->setIsActive(false);
    $user->save();

   $profile = new sfGuardUserProfile();
    $profile->setsfGuardUser($user);
    $profile->setEmail($this->getRequestParameter('user_email'));
    $profile->setRemember($this->getRequestParameter('remember', true));
    $profile->save(); 

    $this->getRequest()->setAttribute('user', $user);
    $raw_email = $this->sendEmail('user', 'registrationConfirmation');  
    $this->logMessage($raw_email, 'debug');    

    $this->setFlash('user_email', $this->getRequestParameter('user_email'));
    $this->redirect('user/askConfirmation');
  }

以下是我的用户个人资料的schema.yml:

sf_guard_user_profile:
  columns:
    id: { type: integer, primary: true, autoincrement: true }
    user_id: { type: integer }
    firstname: { type: string(255) }
    lastname: { type: string(255) }
    user_email: { type: string(255) }
  relations:
    sfGuardUser:
      type: one
      foreignType: one
      class: sfGuardUser
      local: user_id
      foreign: id
      onDelete: cascade
      foreignAlias: Profile

2 个答案:

答案 0 :(得分:0)

尝试更改此行:

$profile->setsfGuardUser($user);

$profile->setSfGuardUser($user);

(注意大写S)

答案 1 :(得分:0)

我看到以下两行与您的架构文件不匹配:

 $profile->setEmail($this->getRequestParameter('user_email'));
$profile->setRemember($this->getRequestParameter('remember', true));

setEmail应该是setUserEmail。 您的架构中不存在setRemember。

修改

我猜错误信息表明以下行是坏的:

$profile->setsfGuardUser($user);

我不确定你是否可以这样做,但是用set方法设置相关的模型。