D
D
davron28132015-04-27 13:33:40
Yii
davron2813, 2015-04-27 13:33:40

How to select a user who is not equal to a given value in Yii 2?

Hello, how can I select a user whose id is not equal to the given parameter, for example, 1
to extract users, I do this

$provider = new ActiveDataProvider([
                'query' => User::find()->where(['id' => 1])  // как можно сделать Неравен 
            ]);
$searchModel = new UserSearch();
        return $this->render('index', [
                        'searchModel' => $searchModel,
                        'dataProvider' => $provider,
        ]);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2015-04-27
@davron2813

'query' => User::find()->where('id != :id', ['id'=>1])

L
LaXiTy, 2017-09-05
@LaXiTy

it’s easier and shorter not to resort to strings, like Alexei’s, but to use the array format
'query' => User::find()->where(['!=', 'id', 1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question