2011-07-21 58 views
0

我正嘗試在我的模式中使用單個表格動態添加嵌入表單。動態嵌入表格

什麼,我的意思是,在我的sfGuardUserProfile表,我有無數的字段,以確定用戶是什麼,即practice_id,nurse_id,記住patient_id

所以,就這樣,我試圖動態地添加護士進行實踐。

我有一個練習形式,它擴展了sfGuardUserAdminForm,它擴展了sfGuardUser,這是我可以獲得存儲在sfGuardUser表中的用戶名,密碼等。

在我的practiceForm我嵌入一個practiceProfileform,它顯示我需要從sfGuardUserProfile表中的字段。我希望每個人都在...

這工作正常,我看到兩個表中的字段。

現在,我現在不確定該怎麼做:嵌入護士。我特別不確定如何做到這一點,因爲這些做法和護士將被保存在同一張桌子上。

practiceForm

class Practiceform extends sfGuardUserAdminForm 
{ 
    public function configure() 
    { 
     $form = new PracticeProfileForm($this->getObject()->getProfile()); 
     $this->embedForm('profile', $form); 
    } 
} 

我也有一個nurseForm,再次延長sfGuardUser,嵌入了nurseProfileForm,延伸sfGuardUserProfile得到我需要的字段。

nurseForm

class dentistForm extends sfGuardUserAdminForm 
{ 
    public function configure() 
    { 
     $profileForm = new nurseProfileForm($this->object->Profile); 
     $this->embedForm('profile', $profileForm); 

{ 

}

我的schema.yml如下:

sfGuardUserProfile: 
    actAs: 
    Timestampable: ~ 
    columns: 
    user_id: 
     type: integer(11) 
     notnull: true 
     default: 
     unsigned: false 
     primary: false 
     unique: false 
     autoincrement: false 
    email_new: 
     type: string(255) 
     unique: true 
    firstname: 
     type: string(255) 
    lastname: 
     type: string(255) 
    practice_id: 
     type: integer(11) 
    nurse_name: 
     type: varchar(255) 
    practice_name: 
     type: varchar(255) 
    practice_type: 
     type: varchar(255) 
    validate_at: 
     type: timestamp 
    validate: 
     type: string(33) 
    relations: 
    User: 
     class: sfGuardUser 
     foreign: id 
     local: user_id 
     type: one 
     onDelete: cascade 
     foreignType: one 
     foreignAlias: Profile 
    Practice: 
     class: sfGuardUserProfile 
     foreign: id 
     local: practice_id 
     type: one 
     onDelete: cascade 
    indexes: 
    validate: 
     fields: [validate] 

有沒有一種簡單的方法來實現與模式/形態我目前動態地將這些護士有使用Doctrine/SF1.4?

梅奈謝謝

回答

0

我強烈建議先重新考慮你的模式。你真的需要將所有實體存儲在一張表中嗎?

相反,具有與sfGuardUser相關的具體字段的不同實體(類)。例如:

Nurse: 
    columns: 
    account_id: integer(4) 
    name: string(255) 
    ... 
    relations: 
    Account: 
     class: sfGuardUser 
     local: account_id 
     foreign: id 
     type: one 
     foreignType: one 

然後,你可以在你的sfGuardUserForm嵌入護士關係:

class sfGuardUserForm 
{ 
    public function configure() 
    { 
     $this->embedRelation('Nurse'); 
    } 
} 

或者,周圍的其他方法:

class NurseForm 
{ 
    public function configure() 
    { 
     $this->embedRelation('Account'); 
    } 
} 

而對於所有其他做同樣的實體。但是,如果你覺得你的國籍幾乎相同,你可以看一下教義的繼承,雖然它通常是被忽視的。