2

I tried

  <?= $form->field($model, 'q', array('class' => 'form-control input-lg')) ?>

and

  <?= $form->field($model, 'q', ['class' => 'form-control input-lg']) ?>

It gives the following error

ReflectionException Class form-control input-lg does not exist

The docs were no help and didn't give examples.

http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#field()-detail

The guide even shows the above format for a button!

http://www.yiiframework.com/doc-2.0/guide-input-forms.html

2 Answers 2

3

When you don't specify any method for field it automatically treats it as a textInput by default.

Use:

<?= $form->field($model, 'q')->textInput(['class' => 'form-control input-lg']); ?>
Sign up to request clarification or add additional context in comments.

3 Comments

How id your answer different from @ıɹnʇɐɹʇıʞuɐ
@crafter I know the answer is same but I tried to explain the reason that's it.
upvote for taking the time to explain what the issue is, in addition to providing a solution.
2

Try this

<?= $form->field($model, 'q')->textInput(['class' => 'form-control input-lg']); ?>

Edit: As suggested by @soju

<?= $form->field($model, 'q', ['inputOptions' => ['class' => 'form-control input-lg']])

1 Comment

Or $form->field($model, 'q', ['inputOptions' => ['class' => 'form-control input-lg']])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.