yiiliveext писал(а): ↑2019.12.26, 18:11
Вообще-то RANDOM делается так
Код: Выделить всё
->orderBy(new \yii\db\Expression('rand()'))
Да, вот так получилось
Код: Выделить всё
public function search($params)
{
$query = Team::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(
[
'query' => $query
]
);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere(
[
'id' => $this->id,
'birth' => $this->birth
]
);
$query->orderBy(new \yii\db\Expression('rand()'));
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'full_name', $this->full_name])
->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
Но есть и другие VIEW, которые используют этот же класса, и как правильно сделать, чтобы у них сортировка была другая, в зависимости от указынных параметров, например, там есть GridView которые тоже позволяет делать свои сортировки и тоже обращается к этому методу,а тут получается я всем это жёстко прописал такую сортировку