[yii2] How to Change a GridView Filter from GET to POST

4 May 2021

Home » Blogs » Technology » [yii2] How to Change a GridView Filter from GET to POST

In yii1, CGridView, by default, if we perform filters from data using the method to request data.

Table of Contents

While on , the default of the filter uses the GET method. Some users may feel uncomfortable with the GET method for a variety of reasons.

To change GridView on from GET to method, you can try it like the following example.

1. View

In the view file add the before and after the grid-like this.

	..............
	..............
	..............
	
     'some-id-you-like',

'timeout' => false,

'enablePushState' = > false,

'clientOptions' => ['method' => 'POST'] ]); 
		
?>

    = GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' = > $searchModel,
        'columns' => [
            ..............
			..............
            ..............
        ],
    ]); 
	?>

    

..............
	..............
	..............

2. Controller

On the switch controller

$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

with

$dataProvider = $searchModel->search(Yii::$app->request->post());

It’s easy enough, isn’t it???? Good luck…

TOP TUTORIALS:  How to Reset Windows 11 Without Admin Password

0 Comments