Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony1 symfony:方法的问题';嵌入关系';_Symfony1_Foreign Keys_Nested Forms - Fatal编程技术网

Symfony1 symfony:方法的问题';嵌入关系';

Symfony1 symfony:方法的问题';嵌入关系';,symfony1,foreign-keys,nested-forms,Symfony1,Foreign Keys,Nested Forms,我有两个一对多的类。我想制作一个嵌套的表单来输入一个对象和其他一些链接到它的对象 但是当我保存表单时,引用我的主类的键没有用主类的键更新。但是,会创建其他关键点 我的模式: Enfant: connection: doctrine tableName: enfant columns: id: type: integer(2) fixed: false unsigned: true primary: true auto

我有两个一对多的类。我想制作一个嵌套的表单来输入一个对象和其他一些链接到它的对象

但是当我保存表单时,引用我的主类的键没有用主类的键更新。但是,会创建其他关键点

我的模式:

Enfant:
  connection: doctrine
  tableName: enfant
  columns:
    id:
      type: integer(2)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    nudparent:
      type: string(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Locataire:
      local: nudparent
      foreign: nud
      type: one
Locataire:
  connection: doctrine
  tableName: locataire
  columns:
    nud:
      type: string(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    nbenfants:
      type: integer(1)
      fixed: false
      unsigned: true
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Bail:
      local: nud
      foreign: locataire
      type: many
    Enfant:
      local: nud
      foreign: nudparent
      type: many
    Refus:
      local: nud
      foreign: nud
      type: many
及制作表格:

$subForm = new sfForm();
for ($i = 0; $i < 2; $i++)
{
    $enfant = new Enfant();
    $enfant->Locataire = $this->getObject();

    $form = new EnfantForm($enfant);

    $subForm->embedForm($i, $form);
 }
 $this->embedForm('new', $subForm);
$subForm=new sfForm();
对于($i=0;$i<2;$i++)
{
$enfant=新儿童();
$enfant->Locataire=$this->getObject();
$form=新儿童表格($enfant);
$subForm->embedForm($i,$form);
}
$this->embedForm('new',$subForm);

您需要使用EmbedderRelation。您可以在此处找到更多信息和示例:

请发布Locataire架构好吗?+1,我对许多表单都有相同的问题,我必须执行类似“parent->setChild($child);”的操作,然后再次保存父级以使其正常工作。我认为,如果子对象引用了父对象,而不是相反,则这种自动保存是有效的。@johnwards:我已经发布了Locataire架构,我看不出您想要什么@格雷戈尔:在教程中,我看到我们可以做到这一点,但当我做同样的事情时,它就没有了work@gregOire:你能解释一下你保存嵌套表单的方法吗?我不知道可以用对象初始化表单,所以现在它对我有效。。。以下是我以前所做的:(库有一个information_id列):$library=$this->form->save();/*@var$libraryForm*/$library->setInformation($this->form->getEmbeddedForm('library')->getObject())$库->保存();告诉我这对你有用吗