2011-04-21 39 views
1

我使用的原則和有一個小問題,embedForm自定義表單和更新記錄SF1.4symfony的 - 與embedForm

我已經創建了一個模塊,用戶可以從特定編輯/創建/刪除用戶使用sfDoctrineGuard

形式組是簡單地命名爲manufacturerForm.class.php自定義表單和它延伸sfGuardUserAdminForm

class manaufacturerForm extends sfGuardUserAdminForm 
{ 
public function configure() 
{ 
    $form = new sfGuardUserProfileForm(); 
    $this->embedForm('profile', $form); 

    unset($this['firstname'], //this field is in sfGuardUserProfile is shown in form 
      $this['user_id'], //this field is in sfGuardUserProfile is shown in form 
      $this['is_super_admin'], //this field is in sfGuardUser is not shown 
      $this['is_admin'], // this filed is in sfGuardUser is not shown 
      $this['permissions_list'], //this field is in sfGuardUser is not shown 
      $this['groups_list']);//this field is in sfGuardUser is not shown 
    } 
} 

你能看到我的嵌入sfGuardUserProfileForm裏面我manufacturerForm

我有兩個問題,sfGuardUserProfile有我不想顯示這個特殊的形式,如: firstname, lastname, email_new, created_at, updated_at,但我似乎無法取消他們,因爲他們仍然顯示。

請注意,此管理模塊沒有generator.yml文件。我在editSuccess.php_form.php部分做了所有這些。

我的另一個問題是,當我編輯現有的用戶,並保存一切都很好。這個問題是有,當我嘗試編輯我得到如下:

An object with the same "user_id" already exist. - 這是在sfGuardUserProfile的user_id領域,同樣適用於email_new領域。我得到An object with the same "email_new" already exist.

1)如何取消我不需要的字段?

2)我是否需要覆蓋任何doSave(),updateObject(),saveEmbeddedForms()方法來停止最後一個問題?

感謝

回答

1

從嵌入表單中刪除字段,你需要在表格內sfGuardUserProfileForm做到這一點。這是因爲只有嵌入到manufacturerForm中時才能讀取這些字段。

如果您需要從sfGuardUserProfileForm中刪除您通常不會執行的自定義字段,只需擴展該類,刪除其中的字段並嵌入新的擴展表單。

當您嵌入表單時,您需要傳遞現有的sfGuardUserPofile對象。

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


class manaufacturerProfileForm extends sfGuardUserProfileForm 
{ 
    public function configure() 
    { 
     unset($this['firstname'], //this field is in sfGuardUserProfile is shown in form 
       $this['user_id'], //this field is in sfGuardUserProfile is shown in form 
       $this['is_super_admin'], //this field is in sfGuardUser is not shown 
       $this['is_admin'], // this filed is in sfGuardUser is not shown 
       $this['permissions_list'], //this field is in sfGuardUser is not shown 
       $this['groups_list']);//this field is in sfGuardUser is not shown 
    } 
+0

好的,但我有多個'用戶'可以這麼說,'製造商','供應商'每個需要sfGuardUserProfileForm類的不同領域。我的manaufacturerForm類擴展了什麼類?我的supplierForm類也一樣嗎?我仍然需要來自sfGuardUser的一些字段,以及來自sfGuardUserProfile的其他字段。謝謝 – terrid25 2011-04-21 11:14:54

+0

我已經添加了一個代碼示例,這有幫助嗎? – 2011-04-21 11:41:24

+0

謝謝你。我嘗試了代碼並收到:「sfGuardUser」上的未知記錄屬性/相關組件「sf_guard_user_profile」。這是什麼意思?教條主義,我很新。謝謝 – terrid25 2011-04-21 12:07:52