我有这段代码可以从数据库中找到一个状态为事件且角色为用户的用户
public static function findByUsername($username)
{
return static::find(['username' => $username, 'status' => static::STATUS_ACTIVE, 'role'=>'user']);
}
我需要找到角色不等于“用户”的用户。我该怎么做?
附言:我使用的是 YII2
最佳答案
我想提供另一种解决方案,它对我来说更优雅。从 Yii 1 开始,当我需要检查不等于操作时,我通常使用这种方法。
$models = Book::find()->where('id != :id and type != :type', ['id'=>1, 'type'=>1])->all();
关于php - yii2事件记录查找列不相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962869/