A
A
AlexAll2019-02-21 10:03:40
Yii
AlexAll, 2019-02-21 10:03:40

How to display all users by id in dataProvider in yii2 having an array with user ids?

With the help I get an array with ids of users of this role

$auth = Yii::$app->authManager;
$role = $auth->getUserIdsByRole($name);

How to correctly drive this array into the dataProvider so that all these users can be displayed in the GridView. I try like this but this version is only suitable for single user search
$searchModel = new UserSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $dataProvider->query->andFilterWhere(['id' => 1]);
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Bukharev, 2019-02-21
@AlexAll

$userIdsByRole=$auth->getUserIdsByRole($name);
$dataProvider->query->andFilterWhere(['IN','id',$userIdsByRole]);

A
Arman, 2019-02-21
@Arik

['id' => $auth->getUserIdsByRole($name)]?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question