我需要帮助。我创建了视图,我正在为一种类型的对象创建多个表单。现在我想保存表单,只需一个按钮,然后将这些对象保存到数据库。
这是控制器:
/**
* @Route("/project/{project_id}/string/{id}/edit/", name="StringEdit")
* @Template()
*/
public function editAction($project_id, $id, Request $request)
{
$string = $this->getDoctrine()->getRepository('DomestosTranslatingBundle:String')->find($id);
$translations = $this->getDoctrine()->getRepository('DomestosTranslatingBundle:Translation')->findByString($string);
//$form = $this->createForm(new TranslationType(), $translation);
//$form->handleRequest($request);
$forms = array();
foreach($translations as $translation){
$form = $this->createForm(new TranslationType, $translation);
$form = $form->createView();
$forms[] = $form;
}
return $this->render('DomestosTranslatingBundle:String:edit.html.twig', array(
'forms' => $forms,
'string' => $string,
));
}
观点:
{% extends "::base.html.twig" %}
{% block title %}Edit translations{% endblock %}
{% block body %}
Code: {{string.code}}
<p>
<table>
{% for keylang,lang in string.project.lang %}
{% for key,form in forms %}
{% if key == keylang %}
<tr>
<td>{{lang.title}}</td>
<td>{{form_widget(form.text)}}</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
<p>
{% endblock %}