2
$form = $this->createForm(new OrganizationType(), $entity, array(
        'action' => $this->generateUrl('_control_organization_create'),
        'method' => 'POST',
    ));

    $form->add('submit', 'submit', array('label' => 'Create'));

    return $form;

定义了动作和方法。如何得到这个?在模板引擎树枝中进入自定义渲染?

4

2 回答 2

3

通过调用,

{{ form(form) }}

或者,

{{ form_start(form) }}

使用您添加到表单定义中的action和选项值。method

从文档...

此外,请查看文档的构建表单部分,了解如何通过传递来呈现 HTML 表单

array('form' => $form->createView()) 

到控制器中的渲染助手。

然后,看看Rendering the Form part of the same documentation

还 ...

如果您想在模板中覆盖它们,您必须将正确的值传递给您的form()form_start()助手,如下所示,

{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}

{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
于 2013-09-11T09:45:51.120 回答
0
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) }}
于 2013-09-11T09:49:37.150 回答