Составил sql запрос: PHP: 'SELECT `fio`,`city` FROM `user` WHERE `status` = 10 ORDER BY `fio` REGEXP '^[А-яа-я]' DESC, `city` DESC, `fio` REGEXP '^[A-za-z]' DESC, `fio` Если пишу так, то не распознает регулярку и вылетает ошибка: PHP: $query = User::find() ->where(['status' => User::STATUS_ACTIVE]) ->orderBy('fio "REGEXP ^[А-яа-я]" DESC, city DESC, fio "REGEXP ^[A-za-z]" DESC, fio') ->ALL(); Этот запрос использую в модели: PHP: namespace app\models; use yii\base\Model; use yii\data\ActiveDataProvider; use app\models\User; use Yii; /** * UserSearch represents the model behind the search form of `app\models\User`. */ class UserSearch extends User { public function rules() { return [ [['id', 'dnomer', 'status', 'created_at', 'updated_at'], 'integer'], [['username', 'fio', 'img', 'city', 'mnomer', 'comp', 'dol', 'spec', 'dep', 'vbiz', 'vladbiz', 'country', 'tip', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'verification_token'], 'safe'], ]; } public function scenarios() { return Model::scenarios(); } public function search($params) { //$sql = 'SELECT `fio`,`city` FROM `user` WHERE `status` = 10 ORDER BY `fio` REGEXP '^[А-яа-я]' DESC, `city` DESC, `fio` REGEXP '^[A-za-z]' DESC, `fio` LIMIT 450'; $query = User::find() ->where(['status' => User::STATUS_ACTIVE]) ->orderBy('fio "REGEXP ^[А-яа-я]" DESC, city DESC, fio "REGEXP ^[A-za-z]" DESC, fio') ->ALL(); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => array('pageSize' => 200), // 'sort'=> ['defaultOrder' => [ // 'fio' => 'REGEXP ^[А-яа-я]'. SORT_ASC, // 'city' => SORT_DESC, // 'fio' => 'REGEXP ^[A-za-z]'. SORT_DESC, // ]], ]); $this->load($params); if (!$this->validate()) { return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'dnomer' => $this->dnomer, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'username', $this->username]) ->andFilterWhere(['like', 'fio', $this->fio]) ->andFilterWhere(['like', 'img', $this->img]) ->andFilterWhere(['like', 'city', $this->city]) ->andFilterWhere(['like', 'mnomer', $this->mnomer]) ->andFilterWhere(['like', 'comp', $this->comp]) ->andFilterWhere(['like', 'dol', $this->dol]) ->andFilterWhere(['or like', 'spec', $this->spec]) ->andFilterWhere(['like', 'dep', $this->dep]) ->andFilterWhere(['like', 'vbiz', $this->vbiz]) ->andFilterWhere(['like', 'vladbiz', $this->vladbiz]) ->andFilterWhere(['like', 'country', $this->country]) ->andFilterWhere(['like', 'tip', $this->tip]) ->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; } } Ошибка такого вида: PHP: Database Exception – yii\db\Exception SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fio "REGEXP ^[А-яа-я]"' in 'order clause' The SQL being executed was: SELECT * FROM `user` WHERE `status`=10 ORDER BY `fio "REGEXP ^[А-яа-я]"` DESC, `city` DESC, `fio "REGEXP ^[A-za-z]"` DESC, `fio` Error Info: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'fio "REGEXP ^[А-яа-я]"' in 'order clause' ) ↵ Caused by: PDOException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fio "REGEXP ^[А-яа-я]"' in 'order clause' Как правильно записать ORDER BY `fio` REGEXP '^[А-яа-я]' DESC, `city` DESC, `fio` REGEXP '^[A-za-z]' DESC, `fio` в yii2 ?
А вы точно прочитали, что по ссылке написано? И ошибку которая возникает, точно прочитали? Без этого класса Yii расценивает всю вашу регулярку, как колонку, и заключает в обратные апострофы.
оооохххх.... Код (Text): $query = User::find() ->where(['status' => User::STATUS_ACTIVE]) ->orderBy(new yii\db\Expression('fio "REGEXP ^[А-яа-я]" DESC, city DESC, fio "REGEXP ^[A-za-z]" DESC, fio')) ->ALL(); Что-то в этом роде. PHP нифига не знаете, как и английский, видимо...