Yii2水平形式

时间:2017-02-14 04:45:49

标签: yii2 yii2-advanced-app yii2-basic-app

我想要做的是从bootstrap垂直变为水平形式,这就是我尝试过的:

<?php $form = ActiveForm::begin([
    'layout' => 'horizontal',
    'action' => ['index'],
    'method' => 'get',
    'fieldConfig' => [
        'horizontalCssClasses' => [
            'label' => 'col-sm-2',
            'offset' => 'col-sm-offset-2',
            'wrapper' => 'col-sm-4',
        ],
    ],
]); ?>
    <div class="row">
        <div class="col-md-6">
            <?= $form->field($model, 'firstname') ?>
            <?= $form->field($model, 'lastname') ?>
       </div>
        <div class="col-md-6">
            <?= $form->field($model, 'email') ?>
            <?= $form->field($model, 'bla') ?>
       </div>
    </div>
<?php ActiveForm::end() ?>

但它给了我一个错误设置未知属性:yii \ widgets \ ActiveForm :: layout 请帮忙!!!

2 个答案:

答案 0 :(得分:5)

layout工作ActiveForm选项必须是yii\bootstrap\ActiveForm的实例,而不是yii\widgets\ActiveForm

更改您的use声明。

答案 1 :(得分:3)

在boostrap中你可以使用

<form class="form-inline">  // for inline fields form

<form class="form-horizontal">  // for horizonatal  fields form

例如:

  <?php $form = ActiveForm::begin([
      'layout' => 'horizontal',
      'action' => ['index'],
      'method' => 'get',
      'class' => 'form-horizontal',    
  ]); ?>