คุณลักษณะสองเท่าใน URL การค้นหาใน Yii2

ฉันมีข้อผิดพลาดแปลก ๆ ในเทมเพลตพื้นฐานของ Yii2 ฉันเพิ่งสร้าง gridview ด้วย Gii เมื่อฉันพยายามกรองผลลัพธ์ URL จะเป็นดังนี้: index.php?EmployeeSearch[name]=Adam&EmployeeSearch[name]=&r=employee%2Findex

ตาราง MySql (พนักงาน) คือ:

  • รหัส | int(11) | การเพิ่มอัตโนมัติ
  • user_id | อินท์(11)
  • ชื่อ | วาร์ชาร์(64)

index.php พร้อม GridView:

<?= 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 และแต่ละคอลัมน์ที่ถูกกรอง


person user12418581    schedule 22.11.2019    source แหล่งที่มา
comment
แสดงดัชนี view หน้าคำจำกัดความ 'GridView' ของคุณ   -  person Serghei Leonenco    schedule 23.11.2019
comment
กรุณาแนบแบบฟอร์ม _search ในคำถามของคุณ   -  person Shringiraj Dewangan    schedule 23.11.2019
comment
@SergheiLeonenco ฉันเพิ่งวาง index.php   -  person user12418581    schedule 25.11.2019


คำตอบ (1)


ในแบบฟอร์มการค้นหา ควรเพิ่ม แอตทริบิวต์การกระทำ มิฉะนั้นจะเพิ่มการค้นหาทุกครั้ง

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