后端sfGuardUser模块

时间:2011-06-06 15:43:04

标签: symfony1 symfony-1.4 symfony-forms sfdoctrineguard sfguard

我使用symfony 1.4.11和Doctrine

我在后端有sfGuardUser模块。我有sfGuardUserProfile表。

sfGuardUserProfile:
  connection: doctrine
  tableName: sf_guard_user_profile
  columns:
    id:            { type: integer(4), primary: true, autoincrement: true }
    user_id:       { type: integer(4), notnull: true }
    salutation:    { type: string(10), notnull: true }
    first_name:    { type: string(30), notnull: true }
    last_name:     { type: string(30), notnull: true }
    country:       { type: string(255), notnull: true }
    postcode:      { type: string(10) , notnull: true }
    city:          { type: string(255), notnull: true }
    address:       { type: string()   , notnull: true }
    phone:         { type: string(50) }
    email:         { type: string(255), notnull: true }
    validate:      { type: string(17) }
    banned:        { type: boolean, default: 0 }
    payed_until:   { type: datetime, notnull: true}
  relations:
     User:
      class: sfGuardUser
      foreign: id
      local: user_id
      type: one
      onDelete: cascade
      onUpdate: cascade
      foreignType: one
      foreignAlias: Profile
  indexes:
    user_id_unique:
      fields: [user_id]
      type: unique

SfGuardUser表:

GuardUser:
  actAs: [Timestampable]
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    username:
      type: string(128)
      notnull: true
      unique: true
    algorithm:
      type: string(128)
      default: sha1
      notnull: true
    salt: string(128)
    password: string(128)
    is_active:
      type: boolean
      default: 1
    is_super_admin:
      type: boolean
      default: false
    last_login:
      type: timestamp
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users
    permissions:
      class: sfGuardPermission
      local: user_id
      foreign: permission_id
      refClass: sfGuardUserPermission
      foreignAlias: Users

我有下一个sfGuardUserForm:

  public function configure()
  {

      parent::configure();

  $profileForm = new sfGuardUserProfileForm($this->object->Profile);
  unset($profileForm['user_id'],$profileForm['banned'],$profileForm['validate'],$profileForm['payed_until']);


     $profileForm->widgetSchema['salutation'] = new weWidgetSalutationI18n();
       $profileForm->widgetSchema['country'] = new sfWidgetFormI18nChoiceCountry();
       $profileForm->setDefault('country', 'DE');
  $this->embedForm('Profile', $profileForm);

  }

所以,当我从后端添加新用户时,在我的sfGuardUserProfile表中 user_id = 0 ......

3 个答案:

答案 0 :(得分:1)

尝试这是否适合您:

public function configure()
{
   parent::configure();
   $profile = new sfGuardUserProfile();
   $profile->setUserId($this->getObject()->id);
   $profileForm = new sfGuardUserProfileForm($profile);
   $this->embedForm('Profile', $profileForm);
}

答案 1 :(得分:0)

我不太确定,但是形成了我的头脑,因为你取消了user_id值。

答案 2 :(得分:0)

首先想到的有些事情是:

  • Read this(要定义主键,关键字是primaryKey:true不是primary:true而且不需要将它们定义为自动增量,ORM可以为自己猜测)
  • 不要取消设置user_id或表单的任何ID,默认情况下它们是隐藏的,这样就不会有问题了。

检查那些poitns并查看问题是否仍然存在,如果是这样,我在更改架构时会发现未正确更新的内容(请记住每次修改架构时都要清除缓存并构建所有类)

希望这有帮助!