V
V
Vladimir2016-09-24 00:01:34
Yii
Vladimir, 2016-09-24 00:01:34

How to pass nothing in Yii2 form?

Good day! There is a form:

<?php $form = ActiveForm::begin([
    'action' => ['search'],
]) ?>
<?=$form->field($modelHouse, 'wall')->listBox(['Панель' => 'Панель', 'Кирпич' => 'Кирпич',]) ?>
<?=$form->field($modelHouse, 'city')->dropDownList(['Киев' => 'Киев', 'Винница' => 'Винница',]) ?>
<?=Html::submitButton('Искать!') ?>
<?php ActiveForm::end() ?>

And there is a request:
House::find()->filterWhere(['wall' => $modelHouse->wall, 'city' => $modelHouse->city])->asArray()->all();

For example, the user decided to see what kind of houses there are with walls of all types. It turns out when there is a " listBox " where at the beginning no item is selected, and if nothing is selected, then houses will be searched from both the brick and the panel. But if you select at least one (either a brick or a panel), then again it is impossible not to transfer parameters to the request (more precisely, I don’t know how). Tried adding an empty field to the options, but it counts as " 0 ". Please tell me what to do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2016-09-24
@MasterGerold

I solved it by adding a new fieldnull => 'Все'

A
Anton, 2016-09-24
Reytarovsky @Antonchik

deepdrop will help you

V
Vicom, 2016-09-24
@vicom

..>dropDownList(['Киев' => 'Киев, 'Винница' => 'Винница,]) ?>

after "Vinnitsa" your quote fell off and fell, nail it back, otherwise even the highlighter is indignant

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question