Yii2查询使用非条件

时间:2017-02-07 19:37:25

标签: php yii2

我在yii2

中有这个查询
return static::find()->where(['truck_status' => 1])
        ->all();

现在我想使用

的非条件
return static::find()->where(['truck_status' !=> 1]) //this fails
        ->all();

但它失败了

我如何解决这个问题

3 个答案:

答案 0 :(得分:1)

您可以使用运算符表示法

     return static::find()->where(['<>' , 'truck_status',1]) 
    ->all();

这可能很有用http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html 看看where部分

答案 1 :(得分:1)

您可以使用运算符格式中的条件。

return static::find()
    ->where(['not', ['truck_status' => 1]]) 
    ->all();

基本上你有[$operator, $operand1, $operand2],其中运算符必须是'between','like'等字符串。

操作数取决于您使用的操作符,因此您应该检查documentation

答案 2 :(得分:1)

您可以这样使用:

return static::find()->where(['!=','truck_status','1'])->all();
相关问题