Symfony2 表单按钮配置
Symfony2 Form Button Configuration
通读 Symfony 2.7 best practices(第 27 页)的表单按钮配置,它说:
Form classes should try to be agnostic to where they will be used. This makes them easier to re-use later.
Add buttons in the templates, not in the form classes or the controllers.
我可以看到在 FormTypes 或 Controller 中没有按钮的好处,但是我不知道我们如何做相当于:
->add('save', 'submit', array('label' => 'Create Post'))
在(我假设是 TWIG)模板中。有人可以举个例子说明应该怎么做吗?
就像这样,在你的树枝模板中:
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Save" />
{{ form_end(form) }}
通读 Symfony 2.7 best practices(第 27 页)的表单按钮配置,它说:
Form classes should try to be agnostic to where they will be used. This makes them easier to re-use later. Add buttons in the templates, not in the form classes or the controllers.
我可以看到在 FormTypes 或 Controller 中没有按钮的好处,但是我不知道我们如何做相当于:
->add('save', 'submit', array('label' => 'Create Post'))
在(我假设是 TWIG)模板中。有人可以举个例子说明应该怎么做吗?
就像这样,在你的树枝模板中:
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Save" />
{{ form_end(form) }}