Yii2过滤网格视图,带有多个$ _GET参数

时间:2017-12-12 07:11:46

标签: gridview get yii2 filtering

我试图创建一个超链接(存储在MySQL Innodb表中),以便打开应用了多个过滤器的gridview。使用一个过滤器(所以使用一个$ _GET参数)它正在工作:

library(data.table)

# Melt the Surrogate data, providing useful column names.
surrogate_dat = melt(data.table(Surrogates), 
                id.vars="Primary", 
                value.name="Site", 
                variable.name="nearest_site_group")
#    Primary nearest_site_group  Site
# 1:   sl2.1           nearest1 sl1.1
# 2:   sl4.1           nearest1 sl2.1
# 3:   sl6.1           nearest1 sl3.1
# 4:   sl2.1           nearest2 sl7.1
# 5:   sl4.1           nearest2 sl8.1
# 6:   sl6.1           nearest2 sl9.1

# Merge melted surrogate data with reference list data.
merged_dat = merge(x=surrogate_dat, 
                   y=data.table(TestRefList), 
                   by="Site")
#     Site Primary nearest_site_group        Gauge          LTA
# 1: sl1.1   sl2.1           nearest1 1.1/110.00/1 1.1/110.99/1
# 2: sl2.1   sl4.1           nearest1 2.1/110.00/1 2.1/110.99/1
# 3: sl3.1   sl6.1           nearest1 3.1/110.00/1 3.1/110.99/1
# 4: sl7.1   sl2.1           nearest2 7.1/110.00/1 7.1/110.99/1
# 5: sl8.1   sl4.1           nearest2 8.1/110.00/1 8.1/110.99/1
# 6: sl9.1   sl6.1           nearest2 9.1/110.00/1 9.1/110.99/1

# 'Cast' merged data back to wide form, specifying 3 value variables.
results= dcast(data=merged_dat, 
               formula=Primary ~ nearest_site_group, 
               value.var=c("Site", "Gauge", "LTA"))
#    Primary Site_nearest1 Site_nearest2 Gauge_nearest1 Gauge_nearest2
# 1:   sl2.1         sl1.1         sl7.1   1.1/110.00/1   7.1/110.00/1
# 2:   sl4.1         sl2.1         sl8.1   2.1/110.00/1   8.1/110.00/1
# 3:   sl6.1         sl3.1         sl9.1   3.1/110.00/1   9.1/110.00/1
#    LTA_nearest1 LTA_nearest2
# 1: 1.1/110.99/1 7.1/110.99/1
# 2: 2.1/110.99/1 8.1/110.99/1
# 3: 3.1/110.99/1 9.1/110.99/1

但是我想再添加一个这样的内容:

.../index?Search%5Bfilter1%5D=something%25

$filter1 = ArrayHelper::getValue(Yii::$app->request->getQueryParams(), 'Search.filter1'));

字符串.../index?Search%5Bfilter1%5D=something%25&Search%5Bfilter2%5D=something%25 ... $filter2 = ArrayHelper::getValue(Yii::$app->request->getQueryParams(), 'Search.filter2')); 进入filter1,当然没有找到记录。

我以为我可以简单地从标题栏复制路线/地址,它应该有效。

something%25?Search%5Bfilter2%5D=something%25

更新:如果我用鼠标移动,我已经注意到存储在数据库中的public function actionIndex() { $searchModel = new Search; $dataProvider = $searchModel->search($_GET); Tabs::clearLocalStorage(); Url::remember(); \Yii::$app->session['__crudReturnUrl'] = null; return $this->render('index', [ 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, ]); } 在工具提示中显示为&。当然,它会尝试打开?的链接。我不确定它是否与问题有关,因为我已尝试将其更改为?%26,但没有区别。

你能指点我正确的方向吗?谢谢!

更新:我认为它与to this one相关。

1 个答案:

答案 0 :(得分:0)

尝试将getQueryParams()代替$ _GET传递给搜索模型

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