【问题标题】:Yii2 export after filter gridview过滤gridview后的Yii2导出
【发布时间】:2017-08-02 02:57:59
【问题描述】:

这是我完成过滤后的网址。

http://localhost/VMS/frontend/web/index.php?r=report%2Ffilter&ic_passport=&name=&unit_no=&category=4&purpose=

1) 我试图在 url 中获取参数

$category = Yii::$app->getRequest()->getQueryParam('category');

Yii::$app->request->getParam('category');

Yii::$app->request->get('category');

但它不起作用。我做错了什么吗?

2)假设我想根据 URL 进行查询,以便我只能导出仅被过滤的结果

  `Table1::find()
  ->andwhere(['category_id'=>$category])
  ->andWhere(['visitor_name'=>$visitor_name])
  ->andWhere(['ic'=>$ic_passport])
  ->andWhere(['unit_no'=>$unit_no])
  ->andWhere(['purpose_id'=>$purpose])
  ->all(),`

根据过滤器 url,它会出现类别 4 的结果。但是当我使用自己创建的查询时,它会出现 0 结果,因为其他属性为空白。为什么在 url 中属性可以留空并且可以工作,但在查询中却不能?

更新的解决方案:

  `Table1::find()
  ->andFilterwhere(['category_id'=>$category])
  ->andFilterWhere(['visitor_name'=>$visitor_name])
  ->andFilterWhere(['ic'=>$ic_passport])
  ->andFilterWhere(['unit_no'=>$unit_no])
  ->andFilterWhere(['purpose_id'=>$purpose])
  ->all()`

只需使用->andFilterWhere

【问题讨论】:

    标签: php mysql sql yii yii2


    【解决方案1】:

    1) get()getQueryParam() 肯定可以工作(第一个基本上是第二个的别名) - 如果它不工作,你一定做错了。

    2) 使用andFilterWhere() 而不是andWhere() - 它的工作方式相同,但如果条件中的变量为空,则会被忽略。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多