yii2的gradview点击按钮通过get方法传参给数据库

1、view内的gradview代码,通过给url传参audit_status

<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'cid', 'pub_id', ['label'=>'缩略图','format'=>'raw','value'=>function($m){ return Html::img($m->thumbnail_low_path,['alt' => '缩略图','width' => 80]); }], ['label'=>'审核通过','format'=>'raw','value'=>function($m){ $url='http://'.$_SERVER['HTTP_HOST']."/index.php?r=images%2Fupdate&id=".$m->cid."&audit_status=1";//审核状态为1  return Html::a('审核通过', $url,['class' => 'btn btn-success']); }], ['label'=>'审核不通过','format'=>'raw','value'=>function($m){ $url='http://'.$_SERVER['HTTP_HOST']."/index.php?r=images%2Fupdate&id=".$m->cid."&audit_status=0";//审核状态为0 return Html::a('审核不通过', $url,['class' => 'btn btn-success']); }], //['label'=>'审核状态:1通过0未通过-1未审核','value'=>'audit_status'] , ['class' => 'yii\grid\ActionColumn',], ], ]); ?>

2、在控制器内更新数据表内容,通过get方法获取url的参数

    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        //$model->load(Yii::$app->request->post()) && $model->save();
        //var_dump($model);exit;
        $data = array();
        $get = Yii::$app->request->get();
        $data['IhpTImages']['audit_status'] = $get['audit_status'];
        //var_dump($data);exit;
        $model->load($data);
        var_dump($model->save());
        return $this->redirect(['index']);
    }

你可能感兴趣的:(yii2,get,审核,gradview)