我有问题全名自动完成。 我有一个usertable,它包含firstname,lastname columns.through ajax。Yii2条件与concat
在搜索行动,这是我的代码:
$users = (new Query())
->select('*')
->from($userTable)
->where(['like', 'username', $searchTerm])
->orWhere(['like', 'firstname', $searchTerm])
->orWhere(['like','lastname', $searchTerm])
->andWhere(['<>','id', Yii::$app->user->id])
->andWhere(['status'=>self::STATUS_ACTIVE])
->orderBy('username')
->limit(20)
->all();
我的问题是,当我试图用姓氏渐渐空虚记录搜索名字。
感谢您的支持,我必须保持CONCAT
解决$users = (new Query())
->select('*')
->from($userTable)
->where(['like', 'username', $searchTerm])
->orWhere(['like', "CONCAT(firstname, ' ', lastname)", $searchTerm])
->andWhere(['<>','id', Yii::$app->user->id])
->andWhere(['status'=>self::STATUS_ACTIVE])
->orderBy('username')
->limit(20)
->all();
[This](http://stackoverflow.com/questions/31297668/yii2-gridview-merge-two-columns/3 8130105#38130105)可能会有帮助... –