2012-09-23 36 views
0

我有两个问题,需要一些帮助。重写Symfony窗​​体的保存功能

我有一个由外键引用到第二个表的表:

member_child: 
    _attributes: { phpName: MemberChild } 
    id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true } 
    member_id: { type: INTEGER, size: '11', required: true, foreignTable: member, foreignReference: id } 
    child_id: { type: INTEGER, size: '11', required: true, foreignTable: child, foreignReference: id } 

和儿童:

child: 
    _attributes: { phpName: Child } 
    id: { type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true, onDelete: cascade } 
    username: { type: VARCHAR, size: '45', required: true, defaultValue: '' } 
    display: { type: TINYINT, size: '1', required: true, defaultValue: '1' } 
    ...etc 

(显然这是推进)

现在时,我想创建一个子对象,使用一个表单,我需要做两件事:

  1. 在提交,提交会员ID
  2. 覆盖的DoSave就会功能,这样可以创建子的时候,我也可以创建member_child对象

我怎样才能做到这些问题?

回答

1

我同意,你可以使用像pankar说的embedForm。你也可以覆盖你的表格的保存方法,如下所示:

$this->childForm = new ChildForm(); 
$this->childMemberForm = new ChildMemberForm(); 

//binding, checking if form was sent etc. 

if ($this->childForm->isValid() && $this->childMemberForm->isValid()) 
{ 
    //save method should return saved object 
    $childObject = $this->childForm->save(); 
    //therefore this id could be used by next object 
    $this->childMemberForm->save(childObject->getId()); 
} 

我希望能帮到你!

0

您可以随时在父窗体中使用内置的Symfony功能sfForm::embedForm以保存子窗体,但是我还没有弄清楚正确使用此窗体的方法。

前段时间我遇到的一篇文章实际上给我提供了解决方案。 Have a look,看看它是否符合您的需求。当然这是在学说,但我想它可以很容易地移植在Propel