具有嵌入式关系的表单不会保存Symfony 1.4 Doctrine

时间:2010-12-06 17:30:25

标签: forms doctrine symfony-1.4 symfony-forms

我在混合表单中嵌入了Mutt表单: MixForm.class.php:

$this->embedRelation('Mutt');
$form = new MuttForm(null, array(
    'mix' =>$this->getObject(),
));
$this->embedForm('Mutt', $form);
$this->widgetSchema['Mutt'] = $form->getWidgetSchema();
$this->widgetSchema['Mutt']['mix_id'] = new sfWidgetFormInputHidden();
$this->validatorSchema['Mutt'] = $form->getValidatorSchema();

我需要为Mix表新创建的id表单填充Mutt表中的mix_id字段。

<?php echo $form->renderHiddenFields();?>
<?php echo $form['name']->renderRow();?>
<?php echo $form['parent1']->renderRow();?>
<?php echo $form['parent2']->renderRow();?>
<?php echo $form['parent3']->renderRow();?>
<?php echo $form['parent4']->renderRow();?>
<?php echo $form['parent5']->renderRow();?>
<?php echo $form['Mutt']['creator']->renderRow();?>
<?php echo $form['Mutt']['email']->renderRow();?>
<?php echo $form['Mutt']['website']->renderRow();?>
<?php echo $form['Mutt']['caption']->renderRow();?>
<?php echo $form['Mutt']['photo']->renderRow();?>
<?php echo $form['Mutt']['copyright']->renderRow();?>
<?php echo $form['Mutt']->renderHiddenFields();?>

这是我在modules / mix / actions / actions.class.php

中的行动
public function executeEdit(sfWebRequest $request)
   {
    $this->form = new MixForm();
    if($request->isMethod('post')):
        $this->form->bind($request->getParameter('mix'), $request->getFiles($this->form->getName()));
        if($this->form->isValid()):
            $this->form->save();
            $this->redirect('pure/add');
        endif;
    endif;
   }

表单验证工作正常,但不会保存在任一数据库中。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

您正在为executeEdit定义操作,但processForm是表单验证并保存到数据库的操作。 executeEdit是在编辑现有作业时显示表单的操作。 请参阅:http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10#chapter_10_sub_the_form_action