Symfony 2 + Bootstrap

时间:2013-11-13 10:45:55

标签: php forms twitter-bootstrap symfony

如何调整表单以实现bootstrap?

我的创建表单功能是:

private function createCreateForm(User $entity)
{

    $form = $this->createFormBuilder($entity, array(
        'action' => $this->generateUrl('user_create'),
        'method' => 'POST',
    ))
    ->add('username')
    ->add('email')
    ->add('password', 'repeated', array(
       'first_name'  => 'password',
       'second_name' => 'confirm',
       'type'        => 'password',
    ))
    ->add('submit', 'submit', array('label' => 'Create'))
    ->getForm();
    return $form;
}

我的观点是

{{ form_start(form) }}
    {{ form_row(form.username, { 'attr': {'class': 'form-control', 'placeholder': 'Imię oraz nazwisko'} }) }}
    {{ form_row(form.password, { 'attr': {'class': 'form-control', 'placeholder': 'Password'} }) }}

它适用于用户名而不是密码,有些消息?我如何创建自己的表单?

我的引导程序:

<form action="#" class="form-horizontal">
    <div class="form-body">
        <div class="form-group">
            <label  class="col-md-3 control-label">NAME</label>
            <div class="col-md-4">
                <input type="text" class="form-control" placeholder="NAME
            </div>
        </div>
    <div class="form-actions fluid">
        <div class="col-md-offset-3 col-md-9">
            <button type="submit" class="btn blue">Add</button>
            <button type="button" class="btn default">Anuluj</button>                              
        </div>
    </div>
</form>

1 个答案:

答案 0 :(得分:1)

使用Mopa Bootstrapbundle https://github.com/phiamo/MopaBootstrapBundle

在您的控制器中:

 $this->createForm(
      MyFormType(),
      $entity,
      array('attr' => array('class' => 'form-horizontal'))
 );