Внутренний модуль sfGuardUser - PullRequest
0 голосов
/ 06 июня 2011

Я использую 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 ]

1 голос
/ 07 июня 2011

Попробуйте, если это работает для вас:

public function configure()
{
   parent::configure();
   $profile = new sfGuardUserProfile();
   $profile->setUserId($this->getObject()->id);
   $profileForm = new sfGuardUserProfileForm($profile);
   $this->embedForm('Profile', $profileForm);
}
0 голосов
/ 06 июня 2011

Первое, что пришло в голову:

  • Прочитайте это (для определения первичного ключа используется ключевое слово primaryKey: true, а не primary: true, и им не нужнобыть определенным как автоинкрементный, ORM может угадать это сам)
  • Не сбрасывать user_id или любые идентификаторы форм, они по умолчанию скрыты, поэтому проблем не должно быть.

Проверьте эти poitns и посмотрите, сохраняется ли проблема, если это так, я могу что-то неправильно обновлять при изменении схемы (не забывайте всегда очищать кеш и строить все классы каждый раз, когда вы изменяете свою схему)

Надеюсь, это поможет!

0 голосов
/ 06 июня 2011

Я не совсем уверен, но в верхней части моей головы это потому, что вы сбросили значение user_id.

...