Symfony1 symfony-自定义表单和使用嵌入表单更新记录

Symfony1 symfony-自定义表单和使用嵌入表单更新记录,symfony1,symfony-1.4,Symfony1,Symfony 1.4,我在embedForm使用条令和SF1.4时遇到了一个小问题 我创建了一个模块,用户可以使用sfDoctrineGuard编辑/创建/删除特定组中的用户 该表单只是一个名为manufacturerForm.class.php的自定义表单,它扩展了sfGuardUserAdminForm class manaufacturerForm extends sfGuardUserAdminForm { public function configure() { $form = new sf

我在
embedForm
使用条令和SF1.4时遇到了一个小问题

我创建了一个模块,用户可以使用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
  }
}
您可以看到,我正在我的
manufacturerForm
中嵌入
sfGuardUserProfileForm

我有两个问题,
sfGuardUserProfile
中有一些我不想为此特定表单显示的字段,例如:
firstname、lastname、email\u new、created\u at、updated\u at
,但我似乎无法取消设置它们,因为它们仍然显示

请注意,此管理模块没有
generator.yml
文件。我在
editsucture.php
中完成所有这些,并使用
\u form.php
部分

我的另一个问题是,当我编辑现有用户并保存所有内容时,一切正常。当我尝试编辑时会出现以下问题:

已存在具有相同“用户id”的对象。
-这适用于sfGuardUserProfile中的
用户id
字段,同样适用于
电子邮件\u new
字段。我得到一个与“email\u new”相同的对象。

1) 如何取消设置不需要的字段

2) 我是否需要覆盖任何doSave()、updateObject()、saveEmbeddedForms()方法来停止上一个问题


感谢

要从嵌入表单中删除字段,您需要在表单
sfGuardUserProfileForm
中执行此操作。这是因为这些字段在嵌入
manufacturerForm
时是只读的

如果需要从
sfGuardUserProfileForm
中删除自定义字段(通常不会这样做),只需扩展该类,删除其中的字段并嵌入新的扩展表单即可

嵌入表单时,需要传入现有的SFGuardUserProfile对象

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
     }

要从嵌入表单中删除字段,需要在表单
sfGuardUserProfileForm
中执行此操作。这是因为这些字段在嵌入
manufacturerForm
时是只读的

如果需要从
sfGuardUserProfileForm
中删除自定义字段(通常不会这样做),只需扩展该类,删除其中的字段并嵌入新的扩展表单即可

嵌入表单时,需要传入现有的SFGuardUserProfile对象

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
     }

好的,但我有多个“用户”,可以说,
制造商
供应商
,每个人都需要来自“sfGuardUserProfileForm”类的不同字段。我的ManaufactureForm类扩展了什么类?我的supplierForm课程也是如此?我仍然需要来自sfGuardUser的一些字段,以及来自sfGuardUserProfile的其他字段。谢谢你。我尝试了代码,并在“sfGuardUser”上收到:
未知记录属性/相关组件“sf\u guard\u user\u profile”。这是什么意思?我对教义很陌生。谢谢,也许只是getProfile()而不是getSfGuardUserProfile(),好吧,但我有多个用户,可以说,
制造商
供应商
每个人都需要来自“SfGuardUserProfile”类的不同字段。我的ManaufactureForm类扩展了什么类?我的supplierForm课程也是如此?我仍然需要来自sfGuardUser的一些字段,以及来自sfGuardUserProfile的其他字段。谢谢你。我尝试了代码,并在“sfGuardUser”
上收到:
未知记录属性/相关组件“sf\u guard\u user\u profile”。这是什么意思?我对教义很陌生。谢谢,也许只是getProfile()而不是getSfGuardUserProfile()