How to use dropdown list value


I have in a view a dropdownlist and a link to render other view when i click in a button. How can i pass the selected value to the other view?

$values = ArrayHelper::map(User::find()->all(), ‘id’, ‘name’);


<?= Html::dropdownlist(‘demo’, null, $values) ?>

<?= Html::a(‘link’, [‘link’, ‘var1’ => $this->field(‘demo’, ‘id’), ‘var2’=> “2015”], [‘class’ => ‘btn btn-primary’]) ?>

With static values for the variables the link work ok, it is defined in the controller with var1 and var2 variables.


The easiest way to create a link dynamically using a dropdownList is to create a form using ‘get’ method.

Something like this:

<?= Html::beginForm(['link', 'var2' => 2015], 'get') ?>

<?= Html::dropDownList('var1', null, ArrayHelper::map(User::find()->all(), 'id', 'name')) ?>

<?= Html::submitButton('link', ['class' => 'btn btn-primary']) ?>

<?= Html::endForm() ?>

Not tested, thought …

Thank you very much!

Very easy to implement your solution. One more thing that i learn.

Thank you!