【问题标题】:Double attributes in search url in Yii2Yii2中搜索url中的双重属性
【发布时间】:2019-11-22 22:19:49
【问题描述】:

我在 Yii2 基本模板中有奇怪的错误。我刚刚用 Gii 生成了 gridview。当我尝试过滤结果时,Url 看起来像这样: index.php?EmployeeSearch[name]=Adam&EmployeeSearch[name]=&r=employee%2Findex

MySql 表(员工)是:

  • 标识 |整数(11) |自增
  • user_id |整数(11)
  • 姓名 | varchar(64)

带有 GridView 的 index.php:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [

        [
            'attribute' => 'name',
            'value' => function($model){ return Html::a($model->name,['employee/update','id'=>$model->id],['class'=>'a-block']); },
            'format' => 'raw'
        ],

        ['class' => 'yii\grid\ActionColumn', 'template' => '{delete}', 'contentOptions' =>['class'=>'text-center'], 'headerOptions'=>['style'=>'width: 60px'], 'buttons' => [ 'calendar' => function($url, $model) { return Html::a('<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>',$url); }  ]],
    ],
]); ?>

我不知道为什么EmployeeSearch[name] 出现两次。问题在于每个 GridView 和每个过滤列。

【问题讨论】:

  • 显示你的索引view页面'GridView'定义。
  • 请在您的问题中附上_search表格。
  • @SergheiLeonenco,我刚刚粘贴了 index.php

标签: gridview yii2 yii2-basic-app


【解决方案1】:

在搜索表单中,应添加动作属性。 否则会在每次搜索时添加。

$form = ActiveForm::begin([
            'action' => ['index'],  <-----------
            'method' => 'get',
]);

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多