[英]symfony 2 create custom form how to get form custom element?
$form = $this->createForm(new OrganizationType(), $entity, array(
'action' => $this->generateUrl('_control_organization_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
there is action and method defined. 有定义的动作和方法。 how to get this?
怎么得到这个? in template engine twig into custom render?
在模板引擎树枝成自定义渲染?
By calling, 通过致电,
{{ form(form) }}
Or, 要么,
{{ form_start(form) }}
the action
and method
options values you added to your form definition are used. 使用添加到表单定义中的
action
和method
选项值。
From the documentation ... 从文档中...
Also, check Building The Form section of the documentation to see how to render the HTML form by passing 另外,请查看文档的“ 构建表单”部分 ,以了解如何通过传递HTML表单
array('form' => $form->createView())
to the render helper within your controller. 到控制器中的渲染助手。
Then, take a look at Rendering the Form part of the same documentation . 然后,看一下同一文档的“ 渲染表单”部分 。
Also ... 还...
If you want to override them in your template, you've to pass the right values to your form()
or form_start()
helpers as follow, 如果您想在模板中覆盖它们,则必须按照以下步骤将正确的值传递给
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) }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.