【发布时间】:2017-04-13 11:48:10
【问题描述】:
我正在尝试使用 select2 过滤 yii2 gridview
在模型搜索中我有
->andFilterWhere(['like', 't_persons.functions', $this->functions ])
不幸的是,字符串 (1) 也匹配 10 和 11
如何过滤逗号分隔字段中的整数值?
【问题讨论】:
标签: gridview filter yii2 select2 kartik-v
我正在尝试使用 select2 过滤 yii2 gridview
在模型搜索中我有
->andFilterWhere(['like', 't_persons.functions', $this->functions ])
不幸的是,字符串 (1) 也匹配 10 和 11
如何过滤逗号分隔字段中的整数值?
【问题讨论】:
标签: gridview filter yii2 select2 kartik-v
如果你有一串逗号分隔的值,我会尝试:
->andFilterWhere('t_persons.functions in ('.$this->functions.')')
【讨论】:
要匹配逗号分隔字段中的单个值,请使用 FIND_IN_SET,例如:
SELECT * FROM t_persons WHERE FIND_IN_SET('3', functions);
要将其集成到 Yii2 中,您可以(如果我正确理解您的命名法)使用:
->andFilterWhere(new Expression('FIND_IN_SET(:function_to_find, functions)'))->addParams([':function_to_find' => $this->functions])->asArray()->all();
【讨论】: