Search with links

i need implement a search by attribute “year”, but i need this in links (ex. when i click in link “2017”, $dataProvider return only records with “year” = “2017”), in form search i have:

<?php echo Html::a('2017', '', ['class' => 'year label label-default', 'id' => '2017']) ; ?
<?php echo Html::a('2018', '', ['class' => 'year label label-default', 'id' => '2018']) ; ?>
<?php echo Html::a('2019', '', ['class' => 'year label label-default', 'id' => '2019']) ; ?>

<?php echo $form->field($model, 'minuta'); ?>

etc.......

who implement this search?

then you add filter in your dataprovider query
$query->andFilterWhere(['year' => $year]);

@suphm yes, but how i search with this link i created manually?

  1. Easiest way is to change the link into a dropdown box
    $form->field($model,'year')->dropDownList(['2012'=>2012])

Then you get all the other variables that are in the form.

  1. The other method if you want to use links is to create a hidden field

$form->field($model,'year')->hiddenInput()

Then you js to update the variable and submit the form

<?php Html::a('2018','#',['data-val'=>2018','class'=>'mylink]) ?>

Then add the JS

                  $('mymodel-year').val( this.val('data-val')))
                  $('#myform').submit() })

the only solution I found so far was yours, it’s not perfect but I could not get it any other way. thanks!