ActiveForm 结合GridView SearchModel [ 2.0 版本 ]
代码如下
<?php $form = ActiveForm::begin([
'action' => ['link/sort','page'=>Yii::$app->request->get('page',1)],
'method' => 'post'
]);?>
<?php Pjax::begin(['id'=>'sort']);?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showFooter' => true,
'columns' => [
'linkID',
[
'attribute' => 'title',
'format' => 'html',
'value' => function ($model){
return Html::a($model->title,$model->siteUrl,['target'=>'_blank']);
}
],
'siteUrl:url',
[
'attribute' => 'expire',
'value' => function ($data){
return date('Y-m-d H:i:s',$data->expire);
}
],
[
'attribute' => 'sort',
'format' => 'raw',
'footer' => Html::submitButton('排序',['class'=>'btn btn-md btn-primary']),
'value' => function ($model){
return Html::input('text','Link[sort][' .$model->linkID . ']',$model->sort,['class'=>'form-control text-center width-50']);
}
],
[
'attribute' => 'status',
'value' => function ($model){
return $model->status == 1 ? '有效' : '无效';
}
],
[
'class' => 'yii\grid\ActionColumn',
'template'=>'{view} {update} {delete}',
'header' => '操作',
'buttons'=>[
'view'=> function ($url, $model, $key) {
return Html::a('<button class="btn btn-xs btn-primary"><i class="ace-icon fa fa-eye bigger-120"></i></button>',['link/view','id'=>$model->linkID]);
},
'update'=> function ($url, $model, $key) {
return Html::a('<button class="btn btn-xs btn-warning"><i class="ace-icon fa fa-pencil bigger-120"></i></button>',['link/update','id'=>$model->linkID]);
},
'delete'=>function ($url,$model,$key){
return Html::a('<botton class="btn btn-xs btn-danger"><i class="ace-icon fa fa-times bigger-120"></i></botton>',['link/delete','id'=>$model->linkID],['data-confirm'=>'您真的要删除?']);
}
]
]
],
]); ?>
<?php Pjax::end();?>
<?php $form->end();?>
问题:
GridView中的sort字段我用想给个批量修改功能,因此给sort字段自定义了个input以及增加了排序表单按钮,然后在GridView外围嵌套了一个form,用ActiveForm生成。导致了searchModel搜索的提交地址不正确
这样一来,searchModel定义的搜索功能就跟ActiveForm冲突了
请问怎么解决,或者用什么方法实现
共 1 个回答
recminy 福建福州
注册时间:2014-09-05
最后登录:2021-07-16
在线时长:65小时45分
最后登录:2021-07-16
在线时长:65小时45分
- 粉丝18
- 金钱2435
- 威望20
- 积分3285