我用了第一种方法,发现没有实现模糊查询。用第二种方法实现了。这是怎么回事?求解。
第一种:
$data = static::find()->->where(['like', 'sex', $this->keywords])->orWhere([ 'like', 'name', $this->keywords])->where(['state' => 1])->asArray()->orderBy('create_time', 3)->all();
第二种:
$data = static::find()->where(['sex' => $this->keywords])->orWhere(['name' => $this->keywords])->andWhere(['del' => 0])->asArray()->orderBy('create_time', 3)->all();
我自己理解:where(['sex' => $this->keywords])->orWhere(['name' => $this->keywords])等同于['like', 'sex', $this->keywords],['or', 'like', 'name', $this->keywords]而第一种不能实现的原因在于重复了。
感觉您在百忙之中的阅读,望大神们不吝赐教。