我需要实现一个属性“年”的搜索,但我需要在链接(例如。当我点击链接“2017”时,$dataProvider只返回带有“年份”=“2017”的记录,在index..php中有:
<div class="y-index">
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('app', 'Create Oficios Apqe'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
'id',
'name',
'minuta',
'year',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>
</div>
_search.php
<div class="y-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'minuta') ?>
<?= Html::a('2019', ['index', 'year' => '2019'], ['class' => 'year label label-efault', 'id' => '2019']) ; ?>
<?= Html::a('2018', ['index', 'year' => '2018'], ['class' => 'year label label-default', 'id' => '2018']) ; ?>
<?= Html::a('2017', ['index', 'year' => '2017'], ['class' => 'year label label-default', 'id' => '2017']) ; ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('app', 'Reset'), [Yii::$app->controller->action->id], ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
基本上,我需要一个来自yii网站的例子:
当我点击“教程”选项中的左侧菜单时,链接设置为"https://www.yiiframework.com/wiki?category=3&version=2.0";
当我点击我的菜单"AJAX“后,链接被追加并设置为"https://www.yiiframework.com/wiki?tag=ajax&category=3&version=2.0";
基本上,我需要搜索形式param“年份”与链接,并与连接从形式"_search.php“对齐。
发布于 2019-06-21 20:26:35
您可以传递一个数组作为第二个参数。
Html::a()
在后台使用yii\helpers\Url::to()
创建链接文档。您可以使用任何想要将它们作为数组传递的参数。
Html::a(
'2017',
['', 'year' => '2017'],
['class' => 'year label label-default', 'id' => '2017']
) ;
发布于 2019-06-22 07:12:33
您只需要从它将提交到当前操作的action
表单中删除_search.php
,它将使用表单传递的新搜索参数追加当前查询字符串。
只需更改
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
至
<?php $form = ActiveForm::begin([
'method' => 'get',
]); ?>
https://stackoverflow.com/questions/56712503
复制