连续两个按钮(Bootstrap 形成 Symfony2 的主题)

Two buttons in a row (Bootstrap form theme for Symfony2)

我正在使用 the Bootstrap form theme for Symfony2(bootstrap_3_水平_layout.html.twig):

我在表单上添加了两个按钮:

$builder
    // some code here ... 
    ->add('save', 'submit', ['label' => 'save'])
    ->add('cancel', 'submit', ['label' => 'cancel']);

它们是这样呈现的:

我需要它们位于同一行:

如何实现?

你试过把第二行和第一行放在同一行吗?

像这样:

->add('save', 'submit', ['label' => 'save']) ->add('cancel', 'submit', ['label' => 'cancel']);

只需在保存按钮左侧添加样式浮动即可。这对我有用:

    ->add('save', 'submit', ['label' => 'save', 'attr' => array('style' => 'float: left')])
    ->add('cancel', 'submit', ['label' => 'cancel']);

关注

Symfony Best Practises: Add buttons in the templates, not in the form classes or the controllers.

例如:

{{ form_start(form) }}
  {{ form_widget(form) }}

  <div class="row">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" value="save" class="btn btn-primary">save</button>
      <button type="submit" value="cancel" class="btn btn-default">cancel</button>
    </div>
  </div>
{{ form_end(form) }}