Yii2,GridView,在会话中保存过滤器值
问题描述:
是否有任何解决方案(在会话中)保存过滤器,以便用户回来后可以看到上次使用的过滤器"?
Is there any solution to save filters (in session) so user can see "last used filters" when he come back?
请链接手册或文档,或您的代码.我什么都没找到.
Please link in manual or docs, or your code. I found nothing searching this question.
答
这有点hack,但是可以为我节省过滤器,页面和排序.
This is somewhat a hack, but this saves filter, page and sorting for me.
将其放置在您的控制器中,假设您的模型名为客户:
Place this in your Controller, assuming your Model is called Customer:
$searchModel = new CustomerSearch();
$params = Yii::$app->request->queryParams;
if (count($params) <= 1) {
$params = Yii::$app->session['customerparams'];
if(isset(Yii::$app->session['customerparams']['page']))
$_GET['page'] = Yii::$app->session['customerparams']['page'];
} else {
Yii::$app->session['customerparams'] = $params;
}
$dataProvider = $searchModel->search($params);