具有嵌入关系的表单不会保存 Symfony 1.4 Doctrine
我已将 Mutt 表单嵌入到 Mix 表单中: 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();?>
这是我在 module/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;
}
表单验证工作正常,但不会保存在任一数据库中。 我做错了什么?
I have embedded the Mutt form within 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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在为
executeEdit
定义一个操作,但processForm
是进行表单验证和保存到数据库的操作。executeEdit
是在编辑现有作业时显示表单的操作。请参阅:http://www.symfony-project.org/jobeet /1_4/Doctrine/zh/10#chapter_10_sub_the_form_action
You are defining an action for
executeEdit
, butprocessForm
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