2011-06-06 28 views
0

我使用symfony 1.4.11與Doctrine後端sfGuardUser模塊

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

回答

1

嘗試,如果這對你的作品:

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

謝謝,但它是行不通的(我可以添加新的用戶,但在我的形式我有:'注意:未定義的屬性:sfGuardUserAdminForm :: $ id在' – denys281 2011-06-07 17:46:21

+0

我的錯,更正了答案。 – Dziamid 2011-06-08 08:57:22

+0

謝謝!但它不工作...我找到問題的根源....我使用sfSocialPlugin,並且我編輯'lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.php'並設置類擴展 'sfSocialGuardUser'而不是'PluginsfGuardUser'。對'sfGuardUserTable'做同樣的事情,使它擴展'sfSocialGuardUserTable' ...當我默認情況下它都可以......嗯...... – denys281 2011-06-08 09:21:58

0

我不太確定,但形成我的頂部這是因爲你沒有設置user_id的值。首先浮現在腦海

+0

當我刪除未設置($ USER_ID),我要添加新的用戶,我有外地的用戶,在那裏我可以選擇現有的用戶。 – denys281 2011-06-06 16:05:55

+0

您可以使用$ profileForm = new sfGuardUserProfileForm($ this-> object-> Profile)選擇您的現有用戶; – Arend 2011-06-06 16:34:55

+0

@guiman我試圖用這個模式和形式在其他symfony項目中做到這一點,它是一切ok.But有sfDoctrineGuardPlugin 5.0 – denys281 2011-06-07 08:34:08

0

出頭是:

  • Read this(定義主鍵,關鍵字是PrimaryKey的:真不是主要的:真實,他們不需要被定義爲自動增加的,ORM可以猜到它爲自己)
  • 不要取消設置user_id或窗體的任何ID,他們默認情況下隱藏,所以不應該是一個問題。

檢查這些poitns,看他的問題仍然存在,如果是這樣我cuold是什麼改變架構時(永遠記住清除緩存和每次修改您的架構建立的所有類)不能正常更新

希望這有助於!