开发者

Form with embedded relation won't save Symfony 1.4 Doctrine

I have embedded the Mutt form wit开发者_开发知识库hin the Mix form: 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();

I need the newly created id form for the Mix table to populate the mix_id field in the Mutt table.

<?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();?>

Here is my action in 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;
   }

The form validation works correctly, but it won't save in either database. What am I doing wrong??


You are defining an action for executeEdit, but processForm is the action where form validation and saving to the database occur. executeEdit is the action for displaying a form when editing an existing job. See: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10#chapter_10_sub_the_form_action

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜