【问题标题】:Backend sfGuardUser module后端 sfGuardUser 模块
【发布时间】:2011-06-06 15:43:03
【问题描述】:

我在 Doctrine 中使用 symfony 1.4.11

我在后端有 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 ...

【问题讨论】:

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


    【解决方案1】:

    试试这是否适合你:

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

    【讨论】:

    • 谢谢,但它不起作用(我可以添加新用户,但在我的表单中我有:`Notice: Undefined property: sfGuardUserAdminForm::$id in'
    • 谢谢!但它不起作用......我找到了问题的根源......我使用了 sfSocialPlugin,我编辑 lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.php 并将类设置为扩展 sfSocialGuardUser 而不是 PluginsfGuardUser。对sfGuardUserTable 执行相同操作,使其扩展sfSocialGuardUserTable...当我默认设置时一切正常...嗯...
    【解决方案2】:

    我不太确定,但我认为这是因为您取消了 user_id 值。

    【讨论】:

    • 当我删除 unset($user_id) 并且我想添加新用户时,我有字段 user ,我可以在其中选择现有用户。
    • 你选择你现有的用户 $profileForm = new sfGuardUserProfileForm($this->object->Profile);
    • @guiman 我尝试在其他 symfony 项目中使用此模式和表单来执行此操作,一切正常。但是有 sfDoctrineGuardPlugin 5.0
    【解决方案3】:

    首先想到的是:

    • Read this(定义一个主键,关键字是primaryKey: true 不是primary: true 不需要定义为自增,ORM自己猜)
    • 不要取消设置 user_id 或任何表单的 id,默认情况下它们是隐藏的,所以这应该不是问题。

    检查那些点,看看他的问题是否仍然存在,如果是这样,我可能会在更改架构时没有正确更新(记住每次修改架构时总是清除缓存并构建所有类)

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      相关资源
      最近更新 更多