Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Horizontal form

What I want to do is to change from bootstrap vertical to horizontal form and this is what I've tried:

<?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() ?>

but it gave me an error Setting unknown property: yii\widgets\ActiveForm::layout Please help!!!

like image 940
Chhorn Soro Avatar asked Dec 15 '22 00:12

Chhorn Soro


1 Answers

For layout option to work ActiveForm must be instance of yii\bootstrap\ActiveForm instead of yii\widgets\ActiveForm.

Change your use statement.

like image 162
Bizley Avatar answered Jan 21 '23 19:01

Bizley