$form = $this->createForm(new OrganizationType(), $entity, array(
'action' => $this->generateUrl('_control_organization_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
定义了操作和方法。 如何获得这个? 在模板引擎中 树枝 进入自定义渲染?
通过调用,
{{ form(form) }}
或
{{ form_start(form) }}
将使用添加到表单定义的"action
"和"method
选项"值。
从文档...
另外,请查看文档的"构建表单"部分,了解如何通过传递来呈现 HTML 表单
array('form' => $form->createView())
到控制器中的呈现帮助程序。
然后,查看同一文档的渲染表单部分。
也。。。
如果要在模板中重写它们,则必须将正确的值传递给form()
或form_start()
帮助程序,如下所示:
{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
Return your form like this
return $this->render('Your Bundle name: Your controller name : Your twig file', array(
'form' => $form->createView(),
));
And in your twig file get the form like this:
{{ form(form) }}