我写了这个可以添加到User类的函数.
/** * Finds all users by assignment role * * @param \yii\rbac\Role $role * @return static|null */ public static function findByRole($role) { return static::find() ->join('LEFT JOIN','auth_assignment','auth_assignment.user_id = id') ->where(['auth_assignment.item_name' => $role->name]) ->all(); }