Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

yii 使用 ActiveDataFilter 传递参数进行搜索,不想用json,想搜索多个状态,使用in查询的话,如何传递参数

 $filter = new ActiveDataFilter([
            'searchModel' => 'customappointmentmodelsAppointment'
        ]);
        $filter->filterAttributeName = 'q';
        $filterCondition = null;

        if ($filter->load(Yii::$app->request->get())) {
//            X::result($filter);die;
            $filterCondition = $filter->build(false);

            if ($filterCondition === false) {
                return $filter;
            }
        }

这么设置的,路径直接传q[status]=SUCCESS,这样可以直接搜索到status为SUCCESS状态的,想加in查询或者or查询,不想用json参数,如何传递参数,qstatus = [EXPIRE,CANCEL],这样不可以,具体应该怎么传


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1.如果使用params 传参数的,使用in查询的话,可以这么传参数

q[status][in][]=EXPIRE&q[status][in][]=CANCEL

会生成下面的sql条件

`status`?IN?('EXPIRE',?'CANCEL')

管理端使用

Yii::$app->request->get()

接收参数

2.如果传json的话,使用in查询的话,可以这么传参数

{
    "q": {
        "status": {"in": ["EXPIRE","CANCEL"]}
    }
}

会生成下面的sql条件

`status`?IN?('EXPIRE',?'CANCEL')

管理端使用

Yii::$app->request->getBodyParams()

接收参数


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...