yii2 active record find column not equal

前端 未结 5 1747
轻奢々
轻奢々 2021-02-18 13:41

I have this code to find a user from db which status is active and role is user

public static function findByUsername($username)
{
 return static::find([\'userna         


        
5条回答
  •  故里飘歌
    2021-02-18 13:59

    You can try:

    public static function findByUsername($username)
    {
     $criteria = new CDbCriteria;  
     $criteria->addCondition("username != 'username'");
     $criteria->addCondition("role != 'user'");
     $result = User::model()->find($criteria);
     return $result;
    }
    

    Or:

    public static function findByUsername($username)
    {
      $result=Users::model()->findByAttributes(array('condition'=>"role != 'user',username = '$username'"));
    }
    

提交回复
热议问题